Commit d366d100 authored by Daniel Honsel's avatar Daniel Honsel
Browse files

improved scoping

parent 405577fc
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -970,7 +970,7 @@ LogStatement:
	LOGKEYWORD LPAREN item+=LogItem (COMMA item+=LogItem)* RPAREN;

	// TODO: LogItem is currently treated as template. Try to use FREE_TEXT again and change SimpleSpec somehow.
// This was seems to work and allows parsing constructs like: 
// This way seems to work and allows parsing constructs like: 
// log ( "*** f_1: INFO: OK - random value = " & bit2str(i1) & " ***" );
LogItem:
/*text=FREE_TEXT |*/ template=InLineTemplate;
@@ -1907,7 +1907,6 @@ terminal CSTRING:
terminal fragment STRING_DOUBLEQUOTE:
	DOUBLEQUOTE DOUBLEQUOTE;

	// TODO: complete CHAR
terminal fragment CHAR:
	EXTENDED_ALPHA_NUM | LPAREN | RPAREN | LBRACKET | RBRACKET | SQUAREOPEN | SQUARECLOSE | ' ' | QUESTIONMARK | STAR |
	BACKSLASH | SLASH | MINUS | PLUS | SHARP | AT | COLON | STRINGOP | '=' | GREATERTHAN | LESSTHAN | PERCENT |
@@ -1943,7 +1942,6 @@ terminal fragment HEX:
terminal fragment OCT:
	HEX HEX;

	// TODO: complete EXTENDED_ALPHA_NUM
terminal fragment EXTENDED_ALPHA_NUM:
	ALPHANUM | UNDERSCORE | '.' | COMMA | EXCLAMATIONMARK;

@@ -1965,11 +1963,6 @@ terminal HEX_STRING_OR_MATCH returns ecore::EString:
terminal OCTET_STRING_OR_MATCH returns ecore::EString:
	SINGLEQUOTE OCT_OR_MATCH* SINGLEQUOTE 'O';

	//terminal STRING	: 
//			'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"' |
//			"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
//		; 


/*
 * Enumerations
+2 −2
Original line number Diff line number Diff line
@@ -355,9 +355,9 @@ class TTCN3ScopeHelper {
		} else if (typeReference instanceof UnionDefNamed) {
			list.addAll(typeReference.body.defs)
		} else if (typeReference instanceof RecordOfDefNamed) {
			//TODO: implement!
			// should be impossible, ... or not?
		} else if (typeReference instanceof SetOfDefNamed) {
			//TODO: implement!
			// should be impossible, ... or not?
		}
		return list
	}
+1 −2
Original line number Diff line number Diff line
@@ -74,8 +74,7 @@ public class TTCN3ImportedNamespaceAwareLocalScopeProvider extends ImportedNames
		}
		if (name != null) {
			ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
			result = createImportScope(result, singletonList(localNormalizer), allDescriptions, reference.getEReferenceType(),
					isIgnoreCase(reference));
			result = createImportScope(result, singletonList(localNormalizer), allDescriptions, reference.getEReferenceType(),isIgnoreCase(reference));
		}
		return result;
	}
+44 −6
Original line number Diff line number Diff line
@@ -49,6 +49,9 @@ 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

class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {

@@ -93,14 +96,31 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {
		}
	}

	def IScope scope_FieldExpressionSpec_fieldRef(FieldExpressionSpec field, EReference ref) {
	private def IScope scopeFieldExpressionList(EObject field) {
		val inlineTemplate = field.findDesiredParent(InLineTemplate)
		val template = field.findDesiredParent(TemplateDef)
		val variable = field.findDesiredParent(VarInstance)
		val cField = field.findDesiredParent(FieldExpressionSpec)
		val eField = field.findDesiredParent(FieldExpressionSpec)
		val cField = field.findDesiredParent(FieldConstExpressionSpec)
		val const = field.findDesiredParent(ConstDef)
		val list = newArrayList

		if (cField != null) {
		if (eField != null) {
			val fieldRef = eField.fieldRef
			if (fieldRef instanceof StructFieldDef) {
				if (fieldRef.type != null && fieldRef.type.ref != null) {
					scopeFor(fieldRef.type.scopeReferencedFields)
				}
			} else if (fieldRef instanceof FormalValuePar) {
				if (fieldRef.type != null && fieldRef.type.ref != null) {
					scopeFor(fieldRef.type.scopeReferencedFields)
				}
			} else if (fieldRef instanceof UnionFieldDef) {
				if (fieldRef.type != null && fieldRef.type.ref != null) {
					scopeFor(fieldRef.type.scopeReferencedFields)
				}
			}
		} else if (cField != null) {
			val fieldRef = cField.fieldRef
			if (fieldRef instanceof StructFieldDef) {
				if (fieldRef.type != null && fieldRef.type.ref != null) {
@@ -110,7 +130,13 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {
				if (fieldRef.type != null && fieldRef.type.ref != null) {
					scopeFor(fieldRef.type.scopeReferencedFields)
				}
			} else if (fieldRef instanceof UnionFieldDef) {
				if (fieldRef.type != null && fieldRef.type.ref != null) {
					scopeFor(fieldRef.type.scopeReferencedFields)
				}
			}
		} else if (const != null) {
			scopeFor(const.type.scopeReferencedFields)
		} else if (inlineTemplate != null) {
			inlineTemplate.templateFieldScope(list)
			scopeFor(list)
@@ -122,6 +148,14 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {
		}
	}

	def IScope scope_FieldExpressionSpec_fieldRef(FieldExpressionSpec field, EReference ref) {
		field.scopeFieldExpressionList
	}

	def IScope scope_FieldConstExpressionSpec_fieldRef(FieldConstExpressionSpec field, EReference ref) {
		field.scopeFieldExpressionList
	}

	def IScope scope_TimerRefOrAny_ref(TimerRefOrAny variable, EReference ref) {
		val list = newArrayList
		var parent = variable.eContainer
@@ -252,7 +286,7 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {
		scopeFor((eContainer as SpecElement).directElements)
	}

	private def Iterable<RefValueElement> directElements(RefValueElement it) {
	private def dispatch Iterable<RefValueElement> directElements(RefValueElement it) {
		switch it {
			FieldReference: directFieldElements
			RefValue: directValueElements
@@ -260,14 +294,14 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {
		}
	}

	private def Iterable<RefValueElement> directElements(RefValueHead it) {
	private def dispatch Iterable<RefValueElement> directElements(RefValueHead it) {
		switch it {
			GroupDef: directGroupElements
			RefValue: directValueElements
		}
	}

	private def Iterable<RefValueElement> directElements(SpecElement it) {
	private def dispatch Iterable<RefValueElement> directElements(SpecElement it) {
		switch it {
			Head: target.directElements
			RefValueTail: value.directElements
@@ -294,6 +328,10 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider {
			if (field.type != null) {
				field.type.scopeReferencedFields
			}
		} else if (field instanceof UnionFieldDef) {
			if (field.type != null) {
				field.type.scopeReferencedFields
			}
		}
	}