Beispiel #1
0
        public override Base VisitVar_spec([NotNull] GolangParser.Var_specContext context)
        {
            var identList = context.identifier_list().Accept(this) as RawNodeList;

            AST.Type type = null;
            if (context.type() != null)
            {
                type = context.type().Accept(this) as AST.Type;
            }

            ExpressionList exprList = null;

            if (context.expression_list() != null)
            {
                exprList = context.expression_list().Accept(this) as ExpressionList;
            }

            var sl = new StatementList();

            for (int i = 0; i < identList.Items.Count; i++)
            {
                VarDeclaration vd;
                if (type != null)
                {
                    vd = new VarDeclaration(identList.Items[i].Text, type.CloneType());
                }
                else //expr list should be defined here
                {
                    vd = new VarDeclaration(identList.Items[i].Text, new ExpressionType(exprList.GetChild <Expression>(0)));
                }

                m_currentScope.AddVarDeclaration(vd);
                if (exprList != null)
                {
                    var assign = new Assignment(
                        new IdentifierExpression(identList.Items[i].Text),
                        exprList.GetChild <Expression>(0),
                        AssignmentType.Normal);

                    if (m_currentScope == m_currentPackage)
                    {
                        m_currentPackage.AddStaticInitializer(assign);
                    }
                    else
                    {
                        sl.AddChild(assign);
                    }
                }
            }
            return(sl);
        }