public void Visit(VariableDeclarationStatement statement)
        {
            var statementDomArg = VisitChild(statement.Expression);

            if (Scope.Current.IsCurrentScopeRegistered(statement.Variable)) //if variable in the same scope is already registered we add an error
                Errors.Add(new VariableAlreadyExists(new Semantic.LineInfo(statement.Line.Line, statement.Line.CharacterPosition), statement.Variable));

            Scope.Current.Register(statement.Variable, statementDomArg.Scope);

            Scope.Current.Type.Type.Members.Add(
               new CodeMemberField() { Name = statement.Variable, Type = statementDomArg.Scope.CodeDomReference, Attributes = MemberAttributes.Public | MemberAttributes.Final });

            var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + statement.Variable), statementDomArg.CodeExpression);

            _codeStack.Peek().Scope = statementDomArg.Scope;
            _codeStack.Peek().ParentStatements.Add(assignment);
        }
示例#2
0
 public void Visit(VariableDeclarationStatement statement, CommonTree tree)
 {
     Parent(tree).Children.Add(statement);
     SetLine(statement, tree);
     statement.Variable = tree.GetChild(0).Text;
     Visit(tree.GetChild(1));
 }