Example #1
0
 public static String GetOuterClassScope(ASTNode node)
 {
     var outer = node.Outer;
     while (outer.Type != ASTNodeType.Class)
         outer = outer.Outer;
     return ((outer as Class).OuterClass as Class).GetInheritanceString();
 }
Example #2
0
 public static Class GetContainingClass(ASTNode node)
 {
     var outer = node.Outer;
     while (outer.Type != ASTNodeType.Class)
         outer = outer.Outer;
     return outer as Class;
 }
Example #3
0
 public CodeBodyParser(TokenStream<String> tokens, CodeBody body, SymbolTable symbols, ASTNode containingNode, MessageLog log = null)
 {
     Log = log ?? new MessageLog();
     Symbols = symbols;
     Tokens = tokens;
     _loopCount = 0;
     _switchCount = 0;
     Node = containingNode;
     Body = body;
     OuterClassScope = NodeUtils.GetOuterClassScope(containingNode);
     // TODO: refactor a better solution to this mess
     if (IsState)
         NodeVariables = (containingNode as State);
     else if (IsFunction)
         NodeVariables = (containingNode as Function);
     else if (IsOperator)
         NodeVariables = (containingNode as OperatorDeclaration);
 }
Example #4
0
 public SymbolReference(ASTNode symbol, SourcePosition start, SourcePosition end, String name = "")
     : base(ASTNodeType.SymbolReference, start, end)
 {
     Node = symbol;
     Name = name;
 }
Example #5
0
 private bool TryGetSymbolInternal(String symbol, out ASTNode node, LinkedList<Dictionary<String, ASTNode>> stack)
 {
     String name = symbol.ToLower();
     LinkedListNode<Dictionary<String, ASTNode>> it;
     for (it = stack.Last; it != null; it = it.Previous)
     {
         if (it.Value.TryGetValue(name, out node))
             return true;
     }
     node = null;
     return false;
 }
Example #6
0
 public void AddSymbol(String symbol, ASTNode node)
 {
     Scopes.Last().Add(symbol.ToLower(), node);
 }
Example #7
0
        public bool TryGetSymbolInScopeStack(String symbol, out ASTNode node, String lowestScope)
        {
            node = null;
            String scope = lowestScope.ToLower();
            if (scope == "object") //As all classes inherit from object this is already checked.
                return false;

            LinkedList<Dictionary<String, ASTNode>> stack;
            if (!TryBuildSpecificScope(scope, out stack))
                return false;

            return TryGetSymbolInternal(symbol, out node, stack);
        }
Example #8
0
 public bool TryGetSymbolFromSpecificScope(String symbol, out ASTNode node, String specificScope)
 {
     node = null;
     Dictionary<String, ASTNode> scope;
     return Cache.TryGetValue(specificScope.ToLower(), out scope) &&
         scope.TryGetValue(symbol.ToLower(), out node);
 }
Example #9
0
 public bool TryGetSymbolFromCurrentScope(String symbol, out ASTNode node)
 {
     return Scopes.Last().TryGetValue(symbol.ToLower(), out node);
 }
Example #10
0
 public bool TryGetSymbol(String symbol, out ASTNode node, String outerScope)
 {
     return TryGetSymbolInternal(symbol, out node, Scopes) ||
         TryGetSymbolInScopeStack(symbol, out node, outerScope);
 }
Example #11
0
 public bool TryAddSymbol(String symbol, ASTNode node)
 {
     if (!SymbolExistsInCurrentScope(symbol.ToLower()))
     {
         AddSymbol(symbol.ToLower(), node);
         return true;
     }
     return false;
 }