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(); }
public static Class GetContainingClass(ASTNode node) { var outer = node.Outer; while (outer.Type != ASTNodeType.Class) outer = outer.Outer; return outer as Class; }
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); }
public SymbolReference(ASTNode symbol, SourcePosition start, SourcePosition end, String name = "") : base(ASTNodeType.SymbolReference, start, end) { Node = symbol; Name = name; }
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; }
public void AddSymbol(String symbol, ASTNode node) { Scopes.Last().Add(symbol.ToLower(), node); }
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); }
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); }
public bool TryGetSymbolFromCurrentScope(String symbol, out ASTNode node) { return Scopes.Last().TryGetValue(symbol.ToLower(), out node); }
public bool TryGetSymbol(String symbol, out ASTNode node, String outerScope) { return TryGetSymbolInternal(symbol, out node, Scopes) || TryGetSymbolInScopeStack(symbol, out node, outerScope); }
public bool TryAddSymbol(String symbol, ASTNode node) { if (!SymbolExistsInCurrentScope(symbol.ToLower())) { AddSymbol(symbol.ToLower(), node); return true; } return false; }