Loading de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/TTCN3.xtext +4 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,10 @@ ConstDef: CONSTKEYWORD type=Type defs=ConstList; Type: pre=PredefinedType | ref=[ReferencedType|QualifiedIdentifier] extensions+=ExtendedFieldReference*; pre=PredefinedType | ref=TypeReference extensions+=ExtendedFieldReference*; TypeReference: head=[ReferencedType|IDENTIFIER] (DOT field=[FieldReference|IDENTIFIER])? array=ArrayOrBitRef? (DOT tail=TypeReference)?; ArrayDef: (SQUAREOPEN expr+=SingleExpression (RANGEOP range+=SingleExpression)? SQUARECLOSE)+; Loading de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/common/TTCN3ScopeHelper.xtend +76 −38 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import de.ugoe.cs.swe.tTCN3.RecordDefNamed import de.ugoe.cs.swe.tTCN3.RecordOfDefNamed import de.ugoe.cs.swe.tTCN3.RefValue import de.ugoe.cs.swe.tTCN3.RefValueElement import de.ugoe.cs.swe.tTCN3.ReferencedType import de.ugoe.cs.swe.tTCN3.SetDefNamed import de.ugoe.cs.swe.tTCN3.SetOfDefNamed import de.ugoe.cs.swe.tTCN3.SignatureDef Loading @@ -45,8 +46,8 @@ import de.ugoe.cs.swe.tTCN3.TemplateDef import de.ugoe.cs.swe.tTCN3.TemplateOrValueFormalPar import de.ugoe.cs.swe.tTCN3.TemplateOrValueFormalParList import de.ugoe.cs.swe.tTCN3.TestcaseDef import de.ugoe.cs.swe.tTCN3.Type import de.ugoe.cs.swe.tTCN3.TypeDef import de.ugoe.cs.swe.tTCN3.TypeReference import de.ugoe.cs.swe.tTCN3.UnionDefNamed import de.ugoe.cs.swe.tTCN3.VarList import java.util.ArrayList Loading Loading @@ -306,6 +307,25 @@ class TTCN3ScopeHelper { scopeFor(list) } def static Iterable<RefValueElement> functionLocalParameter(FunctionDef function) { val list = newArrayList if (function.parameterList == null) return list; for (p : function.parameterList.params) { if (p.timer != null) { list.add(p.timer) } else if (p.value != null) { list.add(p.value) } else if (p.template != null) { list.add(p.template) } else if (p.port != null) { list.add(p.port) } } list } def static void componentScopeValueRefs(ComponentDef component, ArrayList<EObject> list, boolean searchTimer, boolean searchVar) { if (searchVar) { Loading Loading @@ -339,65 +359,63 @@ class TTCN3ScopeHelper { } } def static Iterable<RefValueElement> scopeReferencedFields(Type type) { def static Iterable<RefValueElement> scopeReferencedFields(TypeReference type) { val List<RefValueElement> list = newArrayList val Type originalType = findOriginalType(type) val ReferencedType originalType = findOriginalType(getReferencedType(type)) if (originalType == null) return list; val typeReference = originalType.ref if (typeReference instanceof RecordDefNamed) { list.addAll(typeReference.body.defs) } else if (typeReference instanceof SetDefNamed) { list.addAll(typeReference.body.defs) } else if (typeReference instanceof UnionDefNamed) { list.addAll(typeReference.body.defs) } else if (typeReference instanceof RecordOfDefNamed) { if (originalType instanceof RecordDefNamed) { list.addAll(originalType.body.defs) } else if (originalType instanceof SetDefNamed) { list.addAll(originalType.body.defs) } else if (originalType instanceof UnionDefNamed) { list.addAll(originalType.body.defs) } else if (originalType instanceof RecordOfDefNamed) { // should be impossible, ... or not? } else if (typeReference instanceof SetOfDefNamed) { } else if (originalType instanceof SetOfDefNamed) { // should be impossible, ... or not? } return list } def static void templateFieldScope(TemplateDef template, ArrayList<EObject> list) { val type = findOriginalType(template.base.type) val type = findOriginalType(getReferencedType((template.base.type.ref))) if (type != null && type.ref != null && typeof(RecordDefNamed).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as RecordDefNamed).body.defs) if (type != null && type != null && typeof(RecordDefNamed).isAssignableFrom(type.class)) { list.addAll((type as RecordDefNamed).body.defs) } if (type != null && type.ref != null && typeof(UnionDefNamed).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as UnionDefNamed).body.defs) if (type != null && type != null && typeof(UnionDefNamed).isAssignableFrom(type.class)) { list.addAll((type as UnionDefNamed).body.defs) } if (type != null && type.ref != null && typeof(SignatureDef).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as SignatureDef).paramList.params) if (type != null && type != null && typeof(SignatureDef).isAssignableFrom(type.class)) { list.addAll((type as SignatureDef).paramList.params) } } def static void templateFieldScope(InLineTemplate template, ArrayList<EObject> list) { val type = findOriginalType(template.type) val type = findOriginalType(getReferencedType((template.type.ref))) if (type != null && type.ref != null && typeof(RecordDefNamed).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as RecordDefNamed).body.defs) if (type != null && type != null && typeof(RecordDefNamed).isAssignableFrom(type.class)) { list.addAll((type as RecordDefNamed).body.defs) } if (type != null && type.ref != null && typeof(UnionDefNamed).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as UnionDefNamed).body.defs) if (type != null && type != null && typeof(UnionDefNamed).isAssignableFrom(type.class)) { list.addAll((type as UnionDefNamed).body.defs) } if (type != null && type.ref != null && typeof(SignatureDef).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as SignatureDef).paramList.params) if (type != null && type != null && typeof(SignatureDef).isAssignableFrom(type.class)) { list.addAll((type as SignatureDef).paramList.params) } } // TODO: consider nested types private def static Type findOriginalType(Type type) { if (type != null && type.ref != null && typeof(SubTypeDefNamed).isAssignableFrom(type.ref.class)) { findOriginalType((type.ref as SubTypeDefNamed).type) } else if (type != null && type.ref != null && typeof(RecordOfDefNamed).isAssignableFrom(type.ref.class)) { findOriginalType((type.ref as RecordOfDefNamed).type) } else if (type != null && type.ref != null && typeof(SetOfDefNamed).isAssignableFrom(type.ref.class)) { findOriginalType((type.ref as SetOfDefNamed).setType) private def static ReferencedType findOriginalType(ReferencedType type) { if (type != null && typeof(SubTypeDefNamed).isAssignableFrom(type.class)) { findOriginalType(getReferencedType((type as SubTypeDefNamed).type.ref)) } else if (type != null && typeof(RecordOfDefNamed).isAssignableFrom(type.class)) { findOriginalType(getReferencedType((type as RecordOfDefNamed).type.ref)) } else if (type != null && typeof(SetOfDefNamed).isAssignableFrom(type.class)) { findOriginalType(getReferencedType((type as SetOfDefNamed).setType.ref)) } else { return type; } Loading Loading @@ -431,4 +449,24 @@ class TTCN3ScopeHelper { } } def static ReferencedType getReferencedType(TypeReference reference) { if (reference == null) return null; var TypeReference ref = reference var ReferencedType type = ref.head if (type == null) { return type; } while (ref.tail != null) { ref = ref.tail type = ref.head } return type; } } de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/scoping/TTCN3ScopeProvider.xtend +122 −48 Original line number Diff line number Diff line Loading @@ -3,16 +3,20 @@ 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.BaseTemplate import de.ugoe.cs.swe.tTCN3.CallStatement import de.ugoe.cs.swe.tTCN3.ComponentDef import de.ugoe.cs.swe.tTCN3.ComponentDefList import de.ugoe.cs.swe.tTCN3.ConstDef import de.ugoe.cs.swe.tTCN3.ControlStatementOrDefList import de.ugoe.cs.swe.tTCN3.FieldConstExpressionSpec import de.ugoe.cs.swe.tTCN3.FieldExpressionSpec import de.ugoe.cs.swe.tTCN3.FieldReference import de.ugoe.cs.swe.tTCN3.FieldSpec import de.ugoe.cs.swe.tTCN3.FormalTemplatePar import de.ugoe.cs.swe.tTCN3.FormalTimerPar import de.ugoe.cs.swe.tTCN3.FormalValuePar import de.ugoe.cs.swe.tTCN3.FunctionDef import de.ugoe.cs.swe.tTCN3.FunctionFormalParList import de.ugoe.cs.swe.tTCN3.GroupDef import de.ugoe.cs.swe.tTCN3.Head import de.ugoe.cs.swe.tTCN3.InLineTemplate Loading @@ -21,12 +25,16 @@ import de.ugoe.cs.swe.tTCN3.ModuleDefinition import de.ugoe.cs.swe.tTCN3.ModulePar import de.ugoe.cs.swe.tTCN3.ModuleParDef import de.ugoe.cs.swe.tTCN3.ModuleParameter import de.ugoe.cs.swe.tTCN3.PortDef import de.ugoe.cs.swe.tTCN3.PortOrAny import de.ugoe.cs.swe.tTCN3.PortRef import de.ugoe.cs.swe.tTCN3.RaiseStatement import de.ugoe.cs.swe.tTCN3.RefValue import de.ugoe.cs.swe.tTCN3.RefValueElement import de.ugoe.cs.swe.tTCN3.RefValueHead import de.ugoe.cs.swe.tTCN3.RefValueTail import de.ugoe.cs.swe.tTCN3.ReferencedType import de.ugoe.cs.swe.tTCN3.ReplyStatement import de.ugoe.cs.swe.tTCN3.SendStatement import de.ugoe.cs.swe.tTCN3.SingleTempVarInstance import de.ugoe.cs.swe.tTCN3.SingleVarInstance Loading @@ -35,8 +43,12 @@ import de.ugoe.cs.swe.tTCN3.StructFieldDef import de.ugoe.cs.swe.tTCN3.TemplateDef import de.ugoe.cs.swe.tTCN3.TestcaseDef import de.ugoe.cs.swe.tTCN3.TimerRefOrAny import de.ugoe.cs.swe.tTCN3.TypeReference import de.ugoe.cs.swe.tTCN3.UnionFieldDef import de.ugoe.cs.swe.tTCN3.VarInstance import java.util.ArrayList import java.util.List import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.EReference import org.eclipse.xtext.scoping.IScope import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider Loading @@ -45,17 +57,6 @@ import static org.eclipse.xtext.scoping.Scopes.* import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.* import static extension org.eclipse.xtext.EcoreUtil2.* import org.eclipse.emf.ecore.EObject import de.ugoe.cs.swe.tTCN3.CallStatement import de.ugoe.cs.swe.tTCN3.ReplyStatement import de.ugoe.cs.swe.tTCN3.RaiseStatement import de.ugoe.cs.swe.tTCN3.UnionFieldDef import de.ugoe.cs.swe.tTCN3.FieldConstExpressionSpec import de.ugoe.cs.swe.tTCN3.SingleConstDef import de.ugoe.cs.swe.tTCN3.ArrayOrBitRef import de.ugoe.cs.swe.tTCN3.FormalPortPar import de.ugoe.cs.swe.tTCN3.FunctionFormalParList import de.ugoe.cs.swe.tTCN3.PortDef class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { Loading Loading @@ -89,49 +90,49 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { val fieldRef = eField.fieldRef if (fieldRef instanceof StructFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof FormalValuePar) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof UnionFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } } else if (cField != null) { val fieldRef = cField.fieldRef if (fieldRef instanceof StructFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof FormalValuePar) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof UnionFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } } else if (sField != null) { val fieldRef = sField.ref if (fieldRef instanceof StructFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof FormalValuePar) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof UnionFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } } else if (constDef != null) { scopeFor(constDef.type.scopeReferencedFields) scopeFor(constDef.type.ref.scopeReferencedFields) } else if (inlineTemplate != null) { inlineTemplate.templateFieldScope(list) scopeFor(list) Loading @@ -140,9 +141,9 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { scopeFor(list) } else if (variable != null) { if (variable.type != null && variable.type.ref != null) { scopeFor(variable.type.scopeReferencedFields) scopeFor(variable.type.ref.scopeReferencedFields) } else if (variable.listType != null && variable.listType.ref != null) { scopeFor(variable.listType.scopeReferencedFields) scopeFor(variable.listType.ref.scopeReferencedFields) } } } Loading @@ -156,7 +157,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } def IScope scope_TimerRefOrAny_ref(TimerRefOrAny variable, EReference ref) { val list = newArrayList val ArrayList<EObject> list = newArrayList var parent = variable.eContainer while (parent != null) { Loading Loading @@ -184,6 +185,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { if (parent.system != null) { componentScopeValueRefs(parent.system.component, list, true, false) } list.addAll(parent.functionLocalParameter) } else if (parent instanceof ComponentDef) { for (ComponentDefList l : parent.defs) { if (l.element.timer != null) { Loading @@ -203,6 +205,10 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } parent = parent.eContainer } val function = parent.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } scopeFor(list) } Loading @@ -215,19 +221,43 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } def IScope scope_TimerRefOrAll_ref(AltstepDef altstep, EReference ref) { scopeFor(altstep.eAllOfType(SingleVarInstance), altstep.scopeTimerSpec) val ArrayList<EObject> list = newArrayList val function = altstep.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } list.addAll(altstep.eAllOfType(SingleVarInstance)) scopeFor(list, altstep.scopeTimerSpec) } def scope_StartTimerStatement_ref(AltstepDef altstep, EReference ref) { scopeFor(altstep.eAllOfType(SingleVarInstance), altstep.scopeTimerSpec) val ArrayList<EObject> list = newArrayList val function = altstep.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } list.addAll(altstep.eAllOfType(SingleVarInstance)) scopeFor(list, altstep.scopeTimerSpec) } def IScope scope_TimerRefOrAll_ref(TestcaseDef testcase, EReference ref) { scopeFor(testcase.eAllOfType(SingleVarInstance), testcase.scopeTimerSpec) val ArrayList<EObject> list = newArrayList val function = testcase.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } list.addAll(testcase.eAllOfType(SingleVarInstance)) scopeFor(list, testcase.scopeTimerSpec) } def scope_StartTimerStatement_ref(TestcaseDef testcase, EReference ref) { scopeFor(testcase.eAllOfType(SingleVarInstance), testcase.scopeTimerSpec) val ArrayList<EObject> list = newArrayList val function = testcase.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } list.addAll(testcase.eAllOfType(SingleVarInstance)) scopeFor(list, testcase.scopeTimerSpec) } def IScope scope_PortOrAny_ref(PortOrAny spec, EReference ref) { Loading Loading @@ -267,6 +297,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { val function = statement.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.parameterList.scopeParameterList) list.addAll(function.functionLocalParameter) if (function.runsOn != null) { function.runsOn.component.componentScopePorts(list) } Loading Loading @@ -296,7 +327,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { if (parameter.port != null) { res.add(parameter.port) } else if (parameter.value != null) { // TODO: FormatlValuePar and FormalPortPar are ambiguous, this hack resolves FormalValuePars as Ports too if (parameter.value.type.ref != null && parameter.value.type.ref instanceof PortDef) { if (getReferencedType(parameter.value.type.ref) != null && getReferencedType(parameter.value.type.ref) instanceof PortDef) { res.add(parameter.value) } } Loading @@ -313,15 +344,39 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { if (value != null && typeof(SingleVarInstance).isAssignableFrom(value.target.class)) { val variable = value.target.findDesiredParent(VarInstance) if (variable != null && variable.type != null && variable.type.ref != null) { list.addAll(variable.type.scopeReferencedFields) list.addAll(variable.type.ref.scopeReferencedFields) } else if (variable.listType != null && variable.listType.ref != null) { list.addAll(variable.listType.scopeReferencedFields) list.addAll(variable.listType.ref.scopeReferencedFields) } } } scopeFor(list, pRef.scope_communicationPort) } def IScope scope_TypeReference_field(TypeReference tr, EReference ref) { val parent = tr.eContainer if (parent instanceof TypeReference) { if (parent.field == null) { scopeFor(parent.tail.scopeReferencedFields) } else { IScope.NULLSCOPE } } } def IScope scope_TypeReference_head(TypeReference tr, EReference ref) { val parent = tr.eContainer if (parent instanceof TypeReference) { if (parent.field == null) { scopeFor(parent.tail.getAllContentsOfType(ReferencedType)) } else { IScope.NULLSCOPE } } else { tr.polymorphicFindScopeForClassName(ref) } } def IScope scope_RefValueTail_value(RefValueTail it, EReference ref) { scopeFor((eContainer as SpecElement).directElements) } Loading @@ -348,18 +403,34 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } } private def Iterable<RefValueElement> directValueElements(RefValue template) { if (template instanceof SingleTempVarInstance) { val variable = template.findDesiredParent(VarInstance) private def Iterable<RefValueElement> directValueElements(RefValue value) { if (value instanceof SingleTempVarInstance) { val variable = value.findDesiredParent(VarInstance) if (variable != null && variable.type.ref != null) { variable.type.scopeReferencedFields variable.type.ref.scopeReferencedFields } } else if (template instanceof BaseTemplate) { template.type.scopeReferencedFields } else if (template instanceof SingleVarInstance) { val variable = template.findDesiredParent(VarInstance) } else if (value instanceof BaseTemplate) { value.type.ref.scopeReferencedFields } else if (value instanceof SingleVarInstance) { val variable = value.findDesiredParent(VarInstance) if (variable.listType != null && variable.listType.ref != null) { variable.listType.scopeReferencedFields variable.listType.ref.scopeReferencedFields } } else if (value instanceof StructFieldDef) { if (value.type != null) { value.type.ref.scopeReferencedFields } } else if (value instanceof FormalValuePar) { if (value.type != null) { value.type.ref.scopeReferencedFields } } else if (value instanceof FormalTemplatePar) { if (value.type != null) { value.type.ref.scopeReferencedFields } } else if (value instanceof UnionFieldDef) { if (value.type != null) { value.type.ref.scopeReferencedFields } } } Loading @@ -367,15 +438,19 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { private def Iterable<RefValueElement> directFieldElements(FieldReference field) { if (field instanceof StructFieldDef) { if (field.type != null) { field.type.scopeReferencedFields field.type.ref.scopeReferencedFields } } else if (field instanceof FormalValuePar) { if (field.type != null) { field.type.scopeReferencedFields field.type.ref.scopeReferencedFields } } else if (field instanceof FormalTemplatePar) { if (field.type != null) { field.type.ref.scopeReferencedFields } } else if (field instanceof UnionFieldDef) { if (field.type != null) { field.type.scopeReferencedFields field.type.ref.scopeReferencedFields } } } Loading Loading @@ -417,5 +492,4 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } return list } } Loading
de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/TTCN3.xtext +4 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,10 @@ ConstDef: CONSTKEYWORD type=Type defs=ConstList; Type: pre=PredefinedType | ref=[ReferencedType|QualifiedIdentifier] extensions+=ExtendedFieldReference*; pre=PredefinedType | ref=TypeReference extensions+=ExtendedFieldReference*; TypeReference: head=[ReferencedType|IDENTIFIER] (DOT field=[FieldReference|IDENTIFIER])? array=ArrayOrBitRef? (DOT tail=TypeReference)?; ArrayDef: (SQUAREOPEN expr+=SingleExpression (RANGEOP range+=SingleExpression)? SQUARECLOSE)+; Loading
de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/common/TTCN3ScopeHelper.xtend +76 −38 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import de.ugoe.cs.swe.tTCN3.RecordDefNamed import de.ugoe.cs.swe.tTCN3.RecordOfDefNamed import de.ugoe.cs.swe.tTCN3.RefValue import de.ugoe.cs.swe.tTCN3.RefValueElement import de.ugoe.cs.swe.tTCN3.ReferencedType import de.ugoe.cs.swe.tTCN3.SetDefNamed import de.ugoe.cs.swe.tTCN3.SetOfDefNamed import de.ugoe.cs.swe.tTCN3.SignatureDef Loading @@ -45,8 +46,8 @@ import de.ugoe.cs.swe.tTCN3.TemplateDef import de.ugoe.cs.swe.tTCN3.TemplateOrValueFormalPar import de.ugoe.cs.swe.tTCN3.TemplateOrValueFormalParList import de.ugoe.cs.swe.tTCN3.TestcaseDef import de.ugoe.cs.swe.tTCN3.Type import de.ugoe.cs.swe.tTCN3.TypeDef import de.ugoe.cs.swe.tTCN3.TypeReference import de.ugoe.cs.swe.tTCN3.UnionDefNamed import de.ugoe.cs.swe.tTCN3.VarList import java.util.ArrayList Loading Loading @@ -306,6 +307,25 @@ class TTCN3ScopeHelper { scopeFor(list) } def static Iterable<RefValueElement> functionLocalParameter(FunctionDef function) { val list = newArrayList if (function.parameterList == null) return list; for (p : function.parameterList.params) { if (p.timer != null) { list.add(p.timer) } else if (p.value != null) { list.add(p.value) } else if (p.template != null) { list.add(p.template) } else if (p.port != null) { list.add(p.port) } } list } def static void componentScopeValueRefs(ComponentDef component, ArrayList<EObject> list, boolean searchTimer, boolean searchVar) { if (searchVar) { Loading Loading @@ -339,65 +359,63 @@ class TTCN3ScopeHelper { } } def static Iterable<RefValueElement> scopeReferencedFields(Type type) { def static Iterable<RefValueElement> scopeReferencedFields(TypeReference type) { val List<RefValueElement> list = newArrayList val Type originalType = findOriginalType(type) val ReferencedType originalType = findOriginalType(getReferencedType(type)) if (originalType == null) return list; val typeReference = originalType.ref if (typeReference instanceof RecordDefNamed) { list.addAll(typeReference.body.defs) } else if (typeReference instanceof SetDefNamed) { list.addAll(typeReference.body.defs) } else if (typeReference instanceof UnionDefNamed) { list.addAll(typeReference.body.defs) } else if (typeReference instanceof RecordOfDefNamed) { if (originalType instanceof RecordDefNamed) { list.addAll(originalType.body.defs) } else if (originalType instanceof SetDefNamed) { list.addAll(originalType.body.defs) } else if (originalType instanceof UnionDefNamed) { list.addAll(originalType.body.defs) } else if (originalType instanceof RecordOfDefNamed) { // should be impossible, ... or not? } else if (typeReference instanceof SetOfDefNamed) { } else if (originalType instanceof SetOfDefNamed) { // should be impossible, ... or not? } return list } def static void templateFieldScope(TemplateDef template, ArrayList<EObject> list) { val type = findOriginalType(template.base.type) val type = findOriginalType(getReferencedType((template.base.type.ref))) if (type != null && type.ref != null && typeof(RecordDefNamed).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as RecordDefNamed).body.defs) if (type != null && type != null && typeof(RecordDefNamed).isAssignableFrom(type.class)) { list.addAll((type as RecordDefNamed).body.defs) } if (type != null && type.ref != null && typeof(UnionDefNamed).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as UnionDefNamed).body.defs) if (type != null && type != null && typeof(UnionDefNamed).isAssignableFrom(type.class)) { list.addAll((type as UnionDefNamed).body.defs) } if (type != null && type.ref != null && typeof(SignatureDef).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as SignatureDef).paramList.params) if (type != null && type != null && typeof(SignatureDef).isAssignableFrom(type.class)) { list.addAll((type as SignatureDef).paramList.params) } } def static void templateFieldScope(InLineTemplate template, ArrayList<EObject> list) { val type = findOriginalType(template.type) val type = findOriginalType(getReferencedType((template.type.ref))) if (type != null && type.ref != null && typeof(RecordDefNamed).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as RecordDefNamed).body.defs) if (type != null && type != null && typeof(RecordDefNamed).isAssignableFrom(type.class)) { list.addAll((type as RecordDefNamed).body.defs) } if (type != null && type.ref != null && typeof(UnionDefNamed).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as UnionDefNamed).body.defs) if (type != null && type != null && typeof(UnionDefNamed).isAssignableFrom(type.class)) { list.addAll((type as UnionDefNamed).body.defs) } if (type != null && type.ref != null && typeof(SignatureDef).isAssignableFrom(type.ref.class)) { list.addAll((type.ref as SignatureDef).paramList.params) if (type != null && type != null && typeof(SignatureDef).isAssignableFrom(type.class)) { list.addAll((type as SignatureDef).paramList.params) } } // TODO: consider nested types private def static Type findOriginalType(Type type) { if (type != null && type.ref != null && typeof(SubTypeDefNamed).isAssignableFrom(type.ref.class)) { findOriginalType((type.ref as SubTypeDefNamed).type) } else if (type != null && type.ref != null && typeof(RecordOfDefNamed).isAssignableFrom(type.ref.class)) { findOriginalType((type.ref as RecordOfDefNamed).type) } else if (type != null && type.ref != null && typeof(SetOfDefNamed).isAssignableFrom(type.ref.class)) { findOriginalType((type.ref as SetOfDefNamed).setType) private def static ReferencedType findOriginalType(ReferencedType type) { if (type != null && typeof(SubTypeDefNamed).isAssignableFrom(type.class)) { findOriginalType(getReferencedType((type as SubTypeDefNamed).type.ref)) } else if (type != null && typeof(RecordOfDefNamed).isAssignableFrom(type.class)) { findOriginalType(getReferencedType((type as RecordOfDefNamed).type.ref)) } else if (type != null && typeof(SetOfDefNamed).isAssignableFrom(type.class)) { findOriginalType(getReferencedType((type as SetOfDefNamed).setType.ref)) } else { return type; } Loading Loading @@ -431,4 +449,24 @@ class TTCN3ScopeHelper { } } def static ReferencedType getReferencedType(TypeReference reference) { if (reference == null) return null; var TypeReference ref = reference var ReferencedType type = ref.head if (type == null) { return type; } while (ref.tail != null) { ref = ref.tail type = ref.head } return type; } }
de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/scoping/TTCN3ScopeProvider.xtend +122 −48 Original line number Diff line number Diff line Loading @@ -3,16 +3,20 @@ 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.BaseTemplate import de.ugoe.cs.swe.tTCN3.CallStatement import de.ugoe.cs.swe.tTCN3.ComponentDef import de.ugoe.cs.swe.tTCN3.ComponentDefList import de.ugoe.cs.swe.tTCN3.ConstDef import de.ugoe.cs.swe.tTCN3.ControlStatementOrDefList import de.ugoe.cs.swe.tTCN3.FieldConstExpressionSpec import de.ugoe.cs.swe.tTCN3.FieldExpressionSpec import de.ugoe.cs.swe.tTCN3.FieldReference import de.ugoe.cs.swe.tTCN3.FieldSpec import de.ugoe.cs.swe.tTCN3.FormalTemplatePar import de.ugoe.cs.swe.tTCN3.FormalTimerPar import de.ugoe.cs.swe.tTCN3.FormalValuePar import de.ugoe.cs.swe.tTCN3.FunctionDef import de.ugoe.cs.swe.tTCN3.FunctionFormalParList import de.ugoe.cs.swe.tTCN3.GroupDef import de.ugoe.cs.swe.tTCN3.Head import de.ugoe.cs.swe.tTCN3.InLineTemplate Loading @@ -21,12 +25,16 @@ import de.ugoe.cs.swe.tTCN3.ModuleDefinition import de.ugoe.cs.swe.tTCN3.ModulePar import de.ugoe.cs.swe.tTCN3.ModuleParDef import de.ugoe.cs.swe.tTCN3.ModuleParameter import de.ugoe.cs.swe.tTCN3.PortDef import de.ugoe.cs.swe.tTCN3.PortOrAny import de.ugoe.cs.swe.tTCN3.PortRef import de.ugoe.cs.swe.tTCN3.RaiseStatement import de.ugoe.cs.swe.tTCN3.RefValue import de.ugoe.cs.swe.tTCN3.RefValueElement import de.ugoe.cs.swe.tTCN3.RefValueHead import de.ugoe.cs.swe.tTCN3.RefValueTail import de.ugoe.cs.swe.tTCN3.ReferencedType import de.ugoe.cs.swe.tTCN3.ReplyStatement import de.ugoe.cs.swe.tTCN3.SendStatement import de.ugoe.cs.swe.tTCN3.SingleTempVarInstance import de.ugoe.cs.swe.tTCN3.SingleVarInstance Loading @@ -35,8 +43,12 @@ import de.ugoe.cs.swe.tTCN3.StructFieldDef import de.ugoe.cs.swe.tTCN3.TemplateDef import de.ugoe.cs.swe.tTCN3.TestcaseDef import de.ugoe.cs.swe.tTCN3.TimerRefOrAny import de.ugoe.cs.swe.tTCN3.TypeReference import de.ugoe.cs.swe.tTCN3.UnionFieldDef import de.ugoe.cs.swe.tTCN3.VarInstance import java.util.ArrayList import java.util.List import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.EReference import org.eclipse.xtext.scoping.IScope import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider Loading @@ -45,17 +57,6 @@ import static org.eclipse.xtext.scoping.Scopes.* import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.* import static extension org.eclipse.xtext.EcoreUtil2.* import org.eclipse.emf.ecore.EObject import de.ugoe.cs.swe.tTCN3.CallStatement import de.ugoe.cs.swe.tTCN3.ReplyStatement import de.ugoe.cs.swe.tTCN3.RaiseStatement import de.ugoe.cs.swe.tTCN3.UnionFieldDef import de.ugoe.cs.swe.tTCN3.FieldConstExpressionSpec import de.ugoe.cs.swe.tTCN3.SingleConstDef import de.ugoe.cs.swe.tTCN3.ArrayOrBitRef import de.ugoe.cs.swe.tTCN3.FormalPortPar import de.ugoe.cs.swe.tTCN3.FunctionFormalParList import de.ugoe.cs.swe.tTCN3.PortDef class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { Loading Loading @@ -89,49 +90,49 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { val fieldRef = eField.fieldRef if (fieldRef instanceof StructFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof FormalValuePar) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof UnionFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } } else if (cField != null) { val fieldRef = cField.fieldRef if (fieldRef instanceof StructFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof FormalValuePar) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof UnionFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } } else if (sField != null) { val fieldRef = sField.ref if (fieldRef instanceof StructFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof FormalValuePar) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } else if (fieldRef instanceof UnionFieldDef) { if (fieldRef.type != null && fieldRef.type.ref != null) { scopeFor(fieldRef.type.scopeReferencedFields) scopeFor(fieldRef.type.ref.scopeReferencedFields) } } } else if (constDef != null) { scopeFor(constDef.type.scopeReferencedFields) scopeFor(constDef.type.ref.scopeReferencedFields) } else if (inlineTemplate != null) { inlineTemplate.templateFieldScope(list) scopeFor(list) Loading @@ -140,9 +141,9 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { scopeFor(list) } else if (variable != null) { if (variable.type != null && variable.type.ref != null) { scopeFor(variable.type.scopeReferencedFields) scopeFor(variable.type.ref.scopeReferencedFields) } else if (variable.listType != null && variable.listType.ref != null) { scopeFor(variable.listType.scopeReferencedFields) scopeFor(variable.listType.ref.scopeReferencedFields) } } } Loading @@ -156,7 +157,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } def IScope scope_TimerRefOrAny_ref(TimerRefOrAny variable, EReference ref) { val list = newArrayList val ArrayList<EObject> list = newArrayList var parent = variable.eContainer while (parent != null) { Loading Loading @@ -184,6 +185,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { if (parent.system != null) { componentScopeValueRefs(parent.system.component, list, true, false) } list.addAll(parent.functionLocalParameter) } else if (parent instanceof ComponentDef) { for (ComponentDefList l : parent.defs) { if (l.element.timer != null) { Loading @@ -203,6 +205,10 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } parent = parent.eContainer } val function = parent.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } scopeFor(list) } Loading @@ -215,19 +221,43 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } def IScope scope_TimerRefOrAll_ref(AltstepDef altstep, EReference ref) { scopeFor(altstep.eAllOfType(SingleVarInstance), altstep.scopeTimerSpec) val ArrayList<EObject> list = newArrayList val function = altstep.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } list.addAll(altstep.eAllOfType(SingleVarInstance)) scopeFor(list, altstep.scopeTimerSpec) } def scope_StartTimerStatement_ref(AltstepDef altstep, EReference ref) { scopeFor(altstep.eAllOfType(SingleVarInstance), altstep.scopeTimerSpec) val ArrayList<EObject> list = newArrayList val function = altstep.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } list.addAll(altstep.eAllOfType(SingleVarInstance)) scopeFor(list, altstep.scopeTimerSpec) } def IScope scope_TimerRefOrAll_ref(TestcaseDef testcase, EReference ref) { scopeFor(testcase.eAllOfType(SingleVarInstance), testcase.scopeTimerSpec) val ArrayList<EObject> list = newArrayList val function = testcase.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } list.addAll(testcase.eAllOfType(SingleVarInstance)) scopeFor(list, testcase.scopeTimerSpec) } def scope_StartTimerStatement_ref(TestcaseDef testcase, EReference ref) { scopeFor(testcase.eAllOfType(SingleVarInstance), testcase.scopeTimerSpec) val ArrayList<EObject> list = newArrayList val function = testcase.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.functionLocalParameter) } list.addAll(testcase.eAllOfType(SingleVarInstance)) scopeFor(list, testcase.scopeTimerSpec) } def IScope scope_PortOrAny_ref(PortOrAny spec, EReference ref) { Loading Loading @@ -267,6 +297,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { val function = statement.findDesiredParent(FunctionDef) if (function != null) { list.addAll(function.parameterList.scopeParameterList) list.addAll(function.functionLocalParameter) if (function.runsOn != null) { function.runsOn.component.componentScopePorts(list) } Loading Loading @@ -296,7 +327,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { if (parameter.port != null) { res.add(parameter.port) } else if (parameter.value != null) { // TODO: FormatlValuePar and FormalPortPar are ambiguous, this hack resolves FormalValuePars as Ports too if (parameter.value.type.ref != null && parameter.value.type.ref instanceof PortDef) { if (getReferencedType(parameter.value.type.ref) != null && getReferencedType(parameter.value.type.ref) instanceof PortDef) { res.add(parameter.value) } } Loading @@ -313,15 +344,39 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { if (value != null && typeof(SingleVarInstance).isAssignableFrom(value.target.class)) { val variable = value.target.findDesiredParent(VarInstance) if (variable != null && variable.type != null && variable.type.ref != null) { list.addAll(variable.type.scopeReferencedFields) list.addAll(variable.type.ref.scopeReferencedFields) } else if (variable.listType != null && variable.listType.ref != null) { list.addAll(variable.listType.scopeReferencedFields) list.addAll(variable.listType.ref.scopeReferencedFields) } } } scopeFor(list, pRef.scope_communicationPort) } def IScope scope_TypeReference_field(TypeReference tr, EReference ref) { val parent = tr.eContainer if (parent instanceof TypeReference) { if (parent.field == null) { scopeFor(parent.tail.scopeReferencedFields) } else { IScope.NULLSCOPE } } } def IScope scope_TypeReference_head(TypeReference tr, EReference ref) { val parent = tr.eContainer if (parent instanceof TypeReference) { if (parent.field == null) { scopeFor(parent.tail.getAllContentsOfType(ReferencedType)) } else { IScope.NULLSCOPE } } else { tr.polymorphicFindScopeForClassName(ref) } } def IScope scope_RefValueTail_value(RefValueTail it, EReference ref) { scopeFor((eContainer as SpecElement).directElements) } Loading @@ -348,18 +403,34 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } } private def Iterable<RefValueElement> directValueElements(RefValue template) { if (template instanceof SingleTempVarInstance) { val variable = template.findDesiredParent(VarInstance) private def Iterable<RefValueElement> directValueElements(RefValue value) { if (value instanceof SingleTempVarInstance) { val variable = value.findDesiredParent(VarInstance) if (variable != null && variable.type.ref != null) { variable.type.scopeReferencedFields variable.type.ref.scopeReferencedFields } } else if (template instanceof BaseTemplate) { template.type.scopeReferencedFields } else if (template instanceof SingleVarInstance) { val variable = template.findDesiredParent(VarInstance) } else if (value instanceof BaseTemplate) { value.type.ref.scopeReferencedFields } else if (value instanceof SingleVarInstance) { val variable = value.findDesiredParent(VarInstance) if (variable.listType != null && variable.listType.ref != null) { variable.listType.scopeReferencedFields variable.listType.ref.scopeReferencedFields } } else if (value instanceof StructFieldDef) { if (value.type != null) { value.type.ref.scopeReferencedFields } } else if (value instanceof FormalValuePar) { if (value.type != null) { value.type.ref.scopeReferencedFields } } else if (value instanceof FormalTemplatePar) { if (value.type != null) { value.type.ref.scopeReferencedFields } } else if (value instanceof UnionFieldDef) { if (value.type != null) { value.type.ref.scopeReferencedFields } } } Loading @@ -367,15 +438,19 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { private def Iterable<RefValueElement> directFieldElements(FieldReference field) { if (field instanceof StructFieldDef) { if (field.type != null) { field.type.scopeReferencedFields field.type.ref.scopeReferencedFields } } else if (field instanceof FormalValuePar) { if (field.type != null) { field.type.scopeReferencedFields field.type.ref.scopeReferencedFields } } else if (field instanceof FormalTemplatePar) { if (field.type != null) { field.type.ref.scopeReferencedFields } } else if (field instanceof UnionFieldDef) { if (field.type != null) { field.type.scopeReferencedFields field.type.ref.scopeReferencedFields } } } Loading Loading @@ -417,5 +492,4 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } return list } }