Commit 10823da2 authored by Daniel Honsel's avatar Daniel Honsel
Browse files

fixed value references in conditions

module parameters does not work with this change
parent 5f4005ca
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ TemplateOrValueFormalPar:
	value=FormalValuePar | template=FormalTemplatePar;

ConfigSpec:
	RunsOnSpec spec=SystemSpec?;
	runsOn=RunsOnSpec systemSpec=SystemSpec?;

SystemSpec:
	SYSTEMKEYWORD component=[ComponentDef|IDENTIFIER];
+59 −79
Original line number Diff line number Diff line
@@ -42,41 +42,38 @@ class TTCN3ScopeHelper {
			o.eContainer.findDesiredParent(t)
	}

	def static void scopeModuleVariable(RefValue variable, ArrayList<EObject> list) {
		val container = variable.findDesiredParent(typeof(ModuleDefinitionsList)) as ModuleDefinitionsList
	def static void scopeModuleVariable(ModuleDefinitionsList moduleDef, ArrayList<EObject> list) {

		var defs = container.definitions.filter[it.def instanceof ConstDef]
		var defs = moduleDef.definitions.filter[it.def instanceof ConstDef]
		for (ModuleDefinition v : defs) {
			val constDefList = (v.def as ConstDef).defs as ConstList
			for (EObject d : constDefList.list) {
				if(d != variable) list.add(d)
				list.add(d)
			}
		}

		defs = container.definitions.filter[it.def instanceof TypeDef]
		defs = moduleDef.definitions.filter[it.def instanceof TypeDef]
		for (ModuleDefinition v : defs) {
			val body = (v.def as TypeDef).body
			if (body.structured != null && body.structured.recordOf != null && body.structured.recordOf != variable &&
			if (body.structured != null && body.structured.recordOf != null &&
				body.structured.recordOf instanceof RecordOfDefNamed) {
				list.add(body.structured.recordOf)
			}
			if (body.structured != null && body.structured.setOf != null && body.structured.setOf != variable &&
			if (body.structured != null && body.structured.setOf != null &&
				body.structured.setOf instanceof SetOfDefNamed) {
				list.add(body.structured.setOf)
			}
		}

		defs = container.definitions.filter[it.def instanceof ModuleParDef]
		defs = moduleDef.definitions.filter[it.def instanceof ModuleParDef]
		for (ModuleDefinition v : defs) {
			if ((v.def as ModuleParDef).param != null) {
				for (ModuleParameter p : (v.def as ModuleParDef).param.list.params) {
					if (p != variable)
					list.add(p)
				}
			} else if ((v as ModuleParDef).multitypeParam != null) {
				for (ModulePar p : (v.def as ModuleParDef).multitypeParam.params) {
					for (ModuleParameter pa : p.list.params) {
						if (pa != variable)
						list.add(pa)
					}
				}
@@ -84,93 +81,79 @@ class TTCN3ScopeHelper {
		}
	}

	def static void scopeStatementBlock(RefValue variable, StatementBlock block, ArrayList<EObject> list) {
	def static void scopeStatementBlock(StatementBlock block, ArrayList<EObject> list) {
		for (FunctionDefList l : block.def.filter[it != null]) {
			if (l.locDef != null && l.locDef.constDef != null) {
				val constDefList = l.locDef.constDef.defs as ConstList
				for (SingleConstDef d : constDefList.list) {
					if (d != variable) {
					list.add(d);
				}
			}
			}
			if (l.locInst != null && l.locInst.variable != null) {
				val varList = l.locInst.variable.list as VarList
				for (SingleVarInstance d : varList.variables) {
					if (d != variable) {
					list.add(d);
				}
			}
		}
	}
	}

	def static void scopeInitial(RefValue variable, Initial init, ArrayList<EObject> list) {
	def static void scopeInitial(Initial init, ArrayList<EObject> list) {
		if (init.variable != null) {
			val varList = init.variable.list as VarList
			for (SingleVarInstance d : varList.variables) {
				if (d != variable) {
				list.add(d);
			}
		}
	}
	}

	def static void scopeFunctionParameterValue(RefValue variable, FunctionFormalParList parList,
		ArrayList<EObject> list) {
	def static void scopeFunctionParameterValue(FunctionFormalParList parList, ArrayList<EObject> list) {
		for (FunctionFormalPar p : parList.params.filter[it.value != null]) {
			if (p.value != variable) {
			list.add(p.value);
		}
	}
	}

	def static void scopeModuleControlPart(RefValue variable, ModuleControlPart control, ArrayList<EObject> list) {
	def static void scopeModuleControlPart(ModuleControlPart control, ArrayList<EObject> list) {
		for (ControlStatementOrDefList o : control.body.list) {
			if (o.def.localDef != null && o.def.localDef.constDef != null) {
				val constDefList = o.def.localDef.constDef.defs as ConstList
				for (SingleConstDef d : constDefList.list) {
					if (d != variable) {
					list.add(d);
				}
			}
			}
			if (o.def.localInst != null && o.def.localInst.variable != null) {
				val varList = o.def.localInst.variable.list as VarList
				for (SingleVarInstance d : varList.variables) {
					if (d != variable) {
					list.add(d);
				}
			}
		}
	}
	}

	def static void scopeComponentDef(RefValue variable, ComponentDef component, ArrayList<EObject> list) {
		for (ComponentDefList l : component.defs) {
			if (l.element.const != null) {
				val constDefList = l.element.const.defs as ConstList
				for (SingleConstDef d : constDefList.list) {
					if (d != variable) {
						list.add(d);
					}
				}
			}
			if (l.element.variable != null) {
				val varList = l.element.variable.list as VarList
				for (SingleVarInstance d : varList.variables) {
					if (d != variable) {
						list.add(d);
					}
				}
			}
		}
		for (ComponentDef e : component.extends) {
			scopeComponentDef(variable, e, list)
		}
	}

	def static void scopeTemplateOrValueFormalParList(RefValue variable, TemplateOrValueFormalParList paramsList,
	//	def static void scopeComponentDef(RefValue variable, ComponentDef component, ArrayList<EObject> list) {
	//		for (ComponentDefList l : component.defs) {
	//			if (l.element.const != null) {
	//				val constDefList = l.element.const.defs as ConstList
	//				for (SingleConstDef d : constDefList.list) {
	//					if (d != variable) {
	//						list.add(d);
	//					}
	//				}
	//			}
	//			if (l.element.variable != null) {
	//				val varList = l.element.variable.list as VarList
	//				for (SingleVarInstance d : varList.variables) {
	//					if (d != variable) {
	//						list.add(d);
	//					}
	//				}
	//			}
	//		}
	//		for (ComponentDef e : component.extends) {
	//			scopeComponentDef(variable, e, list)
	//		}
	//	}
	def static void scopeTemplateOrValueFormalParList(TemplateOrValueFormalParList paramsList,
		ArrayList<EObject> list) {
		var RefValue value;

@@ -181,43 +164,38 @@ class TTCN3ScopeHelper {
				value = p.template as RefValue;
			}

			if (value != null && value != variable)
			if (value != null)
				list.add(value);
		}
	}

	def static void scopeAltstepLocalDefList(RefValue variable, AltstepLocalDefList localList, ArrayList<EObject> list) {
	def static void scopeAltstepLocalDefList(AltstepLocalDefList localList, ArrayList<EObject> list) {
		for (AltstepLocalDef a : localList.defs.filter[it != null]) {
			if (a.const != null) {
				val constDefList = a.const.defs as ConstList
				for (SingleConstDef d : constDefList.list) {
					if (d != variable) {
					list.add(d);
				}
			}
			}
			if (a.variable != null) {
				val varList = a.variable.list as VarList
				for (SingleVarInstance d : varList.variables) {
					if (d != variable) {
					list.add(d);
				}
			}
		}
	}
	}

	def static void scopeAltstepExtendedDefList(RefValue variable, AltstepDef altstep, ArrayList<EObject> list) {
	def static void scopeAltstepExtendedDefList(AltstepDef altstep, ArrayList<EObject> list) {
		if (altstep.spec != null) {
			componentScopeValueRefs(altstep.spec.component, list, false)
		}
		if (list.contains(variable)) {
			list.remove(variable)
			componentScopeValueRefs(altstep.spec.component, list, true, true)
		}
	}

	def static void componentScopeValueRefs(ComponentDef component, ArrayList<EObject> list, boolean onlyTimer) {
		if (!onlyTimer) {
	def static void componentScopeValueRefs(ComponentDef component, ArrayList<EObject> list, boolean searchTimer,
		boolean searchVar) {
		if (searchVar) {

			// TODO: template parameters l.element.variable.tempList
			for (ComponentDefList l : component.defs.filter[it.element.variable != null]) {
				if (l.element.variable.list != null) {
@@ -232,13 +210,15 @@ class TTCN3ScopeHelper {
				}
			}
		}
		if (searchTimer) {
			for (ComponentDefList l : component.defs.filter[it.element.timer != null]) {
				for (SingleVarInstance v : l.element.timer.list.variables) {
					list.add(v)
				}
			}
		}
		for (ComponentDef e : component.extends) {
			componentScopeValueRefs(e, list, onlyTimer)
			componentScopeValueRefs(e, list, searchTimer, searchVar)
		}
	}
}
+64 −19
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ package de.ugoe.cs.swe.scoping

import de.ugoe.cs.swe.tTCN3.AltstepDef
import de.ugoe.cs.swe.tTCN3.AltstepLocalDef
import de.ugoe.cs.swe.tTCN3.AltstepLocalDefList
import de.ugoe.cs.swe.tTCN3.ComponentDef
import de.ugoe.cs.swe.tTCN3.ComponentDefList
import de.ugoe.cs.swe.tTCN3.ControlStatementOrDefList
@@ -43,45 +42,92 @@ import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
import static org.eclipse.xtext.scoping.Scopes.*

import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.*
import de.ugoe.cs.swe.tTCN3.ReferencedValue

class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {

	def IScope scope_RefValue(RefValue variable, EReference ref) {
	def IScope scope_ReferencedValue_ref(ReferencedValue value, EReference ref) {
		val list = newArrayList();
		var parent = variable.eContainer
		var parent = value.eContainer

		while (parent != null) {
			if (parent instanceof TTCN3Module) {
				variable.scopeModuleVariable(list)
				parent.defs.scopeModuleVariable(list)
			} else if (parent instanceof StatementBlock) {
				variable.scopeStatementBlock(parent, list)
				parent.scopeStatementBlock(list)
			} else if (parent instanceof Initial) {
				variable.scopeInitial(parent, list)
				parent.scopeInitial(list)
			} else if (parent instanceof ForStatement) {
				variable.scopeInitial(parent.init, list)
				parent.init.scopeInitial(list)
			} else if (parent instanceof FunctionDef) {
				if(parent.parameterList != null) variable.scopeFunctionParameterValue(parent.parameterList, list)
				if(parent.parameterList != null) parent.parameterList.scopeFunctionParameterValue(list)
			} else if (parent instanceof ModuleControlPart) {
				variable.scopeModuleControlPart(parent, list)
				parent.scopeModuleControlPart(list)
			} else if (parent instanceof ComponentDef) {
				variable.scopeComponentDef(parent, list)
				parent.componentScopeValueRefs(list, false, true)
			} else if (parent instanceof TestcaseDef) {
				variable.scopeTemplateOrValueFormalParList(parent.parList, list)
				val ComponentDef comp = parent.spec.runsOn.component
				parent.parList.scopeTemplateOrValueFormalParList(list)
				comp.componentScopeValueRefs(list, false, true)
			} else if (parent instanceof AltstepDef) {
				if(parent.params != null) variable.scopeFunctionParameterValue(parent.params, list)
				variable.scopeAltstepExtendedDefList(parent, list)
			} else if (parent instanceof AltstepLocalDefList) {
				variable.scopeAltstepLocalDefList(parent, list)
				if (parent.params != null) {
					parent.params.scopeFunctionParameterValue(list)
				}
				parent.scopeAltstepExtendedDefList(list)
				parent.local.scopeAltstepLocalDefList(list)
			} else if (parent instanceof GroupDef) {
				variable.scopeModuleVariable(list)
				parent.list.scopeModuleVariable(list)
			}

			parent = parent.eContainer
		}

		scopeFor(list)
	}

	/**
	 * This solution makes the comparison of the defined variable with the assigned variable possible.
	 * It works not well in the case of expressions in if conditions. The solution above works, 
	 * but does not compare the defined variable with the assigned one.
	 */
//	def IScope scope_RefValue(RefValue variable, EReference ref) {
//		val list = newArrayList();
//		var parent = variable.eContainer
//
//		while (parent != null) {
//
//			//			if (parent instanceof TTCN3Module) {
//			//				variable.scopeModuleVariable(list)
//			//			} else if (parent instanceof StatementBlock) {
//			//				variable.scopeStatementBlock(parent, list)
//			//			} else if (parent instanceof Initial) {
//			//				variable.scopeInitial(parent, list)
//			//			} else if (parent instanceof ForStatement) {
//			//				variable.scopeInitial(parent.init, list)
//			//			} else if (parent instanceof FunctionDef) {
//			//				if(parent.parameterList != null) variable.scopeFunctionParameterValue(parent.parameterList, list)
//			//			} else if (parent instanceof ModuleControlPart) {
//			//				variable.scopeModuleControlPart(parent, list)
//			//			} else if (parent instanceof ComponentDef) {
//			//				parent.componentScopeValueRefs(list, variable, false, true)
//			//			else if (parent instanceof TestcaseDef) {
//			//				val ComponentDef comp = parent.spec.runsOn.component
//			//				//variable.scopeTemplateOrValueFormalParList(parent.parList, list)
//			//				comp.componentScopeValueRefs(list, variable, false, true)
//			//			} //else if (parent instanceof AltstepDef) {
//			//				if(parent.params != null) {
//			//					 variable.scopeFunctionParameterValue(parent.params, list)
//			//				}
//			//				variable.scopeAltstepExtendedDefList(parent, list)
//			//				variable.scopeAltstepLocalDefList(parent.local, list)
//			//			} else if (parent instanceof GroupDef) {
//			//				variable.scopeModuleVariable(list)
//			//			}
//			parent = parent.eContainer
//		}
//
//		scopeFor(list)
//	}

	def IScope scope_ReferencedType(ReferencedType type, EReference ref) {
		val module = type.findDesiredParent(typeof(ModuleDefinitionsList)) as TTCN3Module
		val res = newArrayList
@@ -151,7 +197,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {
		while (parent != null) {
			if (parent instanceof AltstepDef) {
				if (parent.spec != null) {
					componentScopeValueRefs(parent.spec.component, list, true)
					componentScopeValueRefs(parent.spec.component, list, true, false)
				}
				for (AltstepLocalDef d : parent.local.defs) {
					if (d.timer != null) {
@@ -168,7 +214,6 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {
						}
					}
				}

			} else if (parent instanceof ModuleControlBody) {
				for (ControlStatementOrDefList l : parent.list) {
					if (l.def.localInst != null && l.def.localInst.timer != null) {
+4 −0
Original line number Diff line number Diff line
@@ -242,6 +242,10 @@ class TTCN3Validator extends AbstractTTCN3Validator {
					error('Name clash with another variable definition in this scope!', feature);
					return;
				}
				if (!parent.spec.runsOn.component.checkNameClashComponentDefHierarchy(variable)) {
					error('Name clash with another variable definition in this scope!', feature);
					return;
				}				
			} else if (parent instanceof TemplateOrValueFormalParList) {
				if (parent.checkNameClashTemplateOrValueFormalParList(variable)) {
					error('Name clash with another variable definition in this scope!', feature);