private void AddMethod(string methodName, string returnType, MethodType type, ModifiersEnum modifiers, ParserRuleContext context, FormalParametersContext parameterContext) { List <Variable> parameters = new List <Variable>(); FormalParameterListContext parameterListContext = parameterContext.formalParameterList(); if (parameterListContext != null) { foreach (var parameter in parameterListContext.formalParameter()) { parameters.Add(new Variable(parameter.variableDeclaratorId().GetText(), parameter.typeType().GetText(), parameter.variableDeclaratorId())); } } Method method = new Method(Class, Class.PopMethodId(), methodName, modifiers, returnType, parameters, context); StatementListener listener = new StatementListener(method); foreach (var methodRule in context.GetRuleContexts <ParserRuleContext>()) { methodRule.EnterRule(listener); } method.Statements = listener.GetResult(); Class.Methods.Add(method.Name, method); }
public override void EnterIfStatement([NotNull] IfStatementContext context) { IfStatement statement = new IfStatement(Parent, context); ExpressionListener listener = new ExpressionListener(statement); context.parExpression().expression().EnterRule(listener); statement.IfCondition = listener.GetResult(); StatementListener statementListener = new StatementListener(statement); context.ifSt.EnterRule(statementListener); statement.IfStatements = statementListener.GetResult(); if (context.elseSt != null) { statementListener = new StatementListener(statement); context.elseSt.EnterRule(statementListener); statement.ElseStatements = statementListener.GetResult(); } Result.Add(statement); }
public override void EnterForStatement([NotNull] ForStatementContext context) { ForStatement statement = new ForStatement(Parent, context); StatementListener statementListener = new StatementListener(statement); context.forControl().forInit.EnterRule(statementListener); statement.Init = statementListener.GetResult().First(); statementListener = new StatementListener(statement); context.statement().EnterRule(statementListener); statement.Statements = statementListener.GetResult(); ExpressionListener expressionListener = new ExpressionListener(statement); context.forControl().forCond.EnterRule(expressionListener); statement.Condition = expressionListener.GetResult(); statementListener = new StatementListener(statement); context.forControl().forUpdate.EnterRule(statementListener); statement.Update = statementListener.GetResult().First(); Result.Add(statement); }