/// <summary> /// Fills the retVal result set according to the subDeclarator class provided as parameter /// </summary> /// <param name="subDeclarator">The subdeclarator used to get the image</param> /// <param name="expectation">The expectatino of the desired element</param> /// <param name="location">The location of the element found</param> /// <param name="values">The return value to update</param> /// <return>the number of elements added</return> private int FillBySubdeclarator(Utils.ISubDeclarator subDeclarator, Filter.AcceptableChoice expectation, ReturnValue values) { int retVal = 0; if (subDeclarator != null) { List <Utils.INamable> tmp = new List <Utils.INamable>(); subDeclarator.Find(Image, tmp); foreach (Utils.INamable namable in tmp) { addReference(namable, expectation, values); retVal += 1; } } return(retVal); }
/// <summary> /// Provides the possible references for this designator (only available during semantic analysis) /// </summary> /// <param name="instance">the instance on which this element should be found.</param> /// <param name="expectation">the expectation on the element found</param> /// <param name="lastElement">Indicates that this element is the last one in a dereference chain</param> /// <returns></returns> public ReturnValue getReferences(INamable instance, Filter.AcceptableChoice expectation, bool lastElement) { ReturnValue retVal = new ReturnValue(this); if (instance == null) { // Special handling for THIS if (Image.CompareTo("THIS") == 0) { INamable currentElem = Root; while (currentElem != null) { Types.Type type = currentElem as Types.Type; if (type != null) { Types.StateMachine stateMachine = type as Types.StateMachine; while (stateMachine != null) { type = stateMachine; stateMachine = stateMachine.EnclosingStateMachine; } retVal.Add(type); return(retVal); } currentElem = enclosing(currentElem); } return(retVal); } // No enclosing instance. Try to first name of a . separated list of names // . First in the enclosing expression InterpreterTreeNode current = this; while (current != null) { ISubDeclarator subDeclarator = current as ISubDeclarator; if (FillBySubdeclarator(subDeclarator, expectation, retVal) > 0) { // If this is the last element in the dereference chain, stop at first match if (lastElement) { return(retVal); } current = null; } else { current = current.Enclosing; } } // . In the predefined elements addReference(EFSSystem.getPredefinedItem(Image), expectation, retVal); if (lastElement && !retVal.IsEmpty) { return(retVal); } // . In the enclosing items, except the enclosing dictionary since dictionaries are handled in a later step INamable currentNamable = Root; while (currentNamable != null) { Utils.ISubDeclarator subDeclarator = currentNamable as Utils.ISubDeclarator; if (subDeclarator != null && !(subDeclarator is Dictionary)) { if (FillBySubdeclarator(subDeclarator, expectation, retVal) > 0 && lastElement) { return(retVal); } } currentNamable = enclosingSubDeclarator(currentNamable); } // . In the dictionaries declared in the system foreach (Dictionary dictionary in EFSSystem.Dictionaries) { if (FillBySubdeclarator(dictionary, expectation, retVal) > 0 && lastElement) { return(retVal); } Types.NameSpace defaultNameSpace = dictionary.findNameSpace("Default"); if (defaultNameSpace != null) { if (FillBySubdeclarator(defaultNameSpace, expectation, retVal) > 0 && lastElement) { return(retVal); } } } } else { // The instance is provided, hence, this is not the first designator in the . separated list of designators if (instance is Types.ITypedElement && !(instance is Constants.State)) { // If the instance is a typed element, dereference it to its corresponding type Types.ITypedElement element = instance as Types.ITypedElement; if (element.Type != EFSSystem.NoType) { instance = element.Type; } } // Find the element in all enclosing sub declarators of the instance while (instance != null) { Utils.ISubDeclarator subDeclarator = instance as Utils.ISubDeclarator; if (FillBySubdeclarator(subDeclarator, expectation, retVal) > 0) { instance = null; } else { if (instance is Dictionary) { instance = enclosingSubDeclarator(instance); } else { instance = null; } } } } return(retVal); }