public override void EnterArgument(CSharpParser.ArgumentContext context) { IToken argumentToken = context.Start; if (symbolTable.FindSymbol(argumentToken, ast) != null) { RuleContext parentContext = context; while ((parentContext = parentContext.Parent) != null) { if (parentContext.GetType() == typeof(CSharpParser.Method_invocationContext)) { break; } } if (parentContext == null) { throw new Exception("Undefined method (WTF!!)"); } //Get method definition to check argument types IToken methodDefinitionToken = ((CSharpParser.Method_declarationContext)parentContext).Start; Node methodDeclarationNode = ast.GetNode(methodDefinitionToken, Node.Kind.MethodVariableDeclaration); if (methodDeclarationNode == null) { throw new Exception("Undefined method symbol"); } //calcule argument position int argumentPosition = 0; RuleContext parentContext_1 = context.Parent; for (int i = 0; i < parentContext_1.ChildCount; i++) { if (parentContext_1.GetChild(i) == context) { break; } else { argumentPosition++; } } if (ast.GetNode(methodDeclarationNode.Children[argumentPosition]).Token.Type != context.Start.Type) { throw new Exception("Type on invoking method doesnt match"); } Node ArgumentNode = new Node(argumentToken, Node.Kind.Argument, null); ast.AddNode(ArgumentNode); ast.GetNode(((CSharpParser.Method_invocationContext)parentContext).Start, Node.Kind.MethodInvocation).AddChildIndex(ast.NodeIndex(ArgumentNode)); } else { throw new Exception("Undefined symbol"); } Console.WriteLine("Entering argument context."); }
public override void ExitArgument(CSharpParser.ArgumentContext context) { Console.WriteLine("Exiting argument context."); }