Exemplo n.º 1
0
        public override void EnterClassvars([NotNull] XSharpParser.ClassvarsContext context)
        {
            // PROTECT a,b as STRING
            // copy type from b to a
            var classVarModifiers = decodeClassVarModifiers(context.Modifiers);

            if (context._Vars.Count > 1)
            {
                XSharpParser.DatatypeContext dtc = null;
                foreach (var classvar in context._Vars.Reverse())
                {
                    if (classvar.DataType != null)
                    {
                        dtc = classvar.DataType;
                    }
                    else
                    {
                        classvar.DataType = dtc;
                    }
                }
            }

            foreach (var varContext in context._Vars)
            {
                var field     = new XCodeMemberField();
                var fieldType = BuildDataType(varContext.DataType);
                field.Name       = varContext.Id.GetText();
                field.Type       = fieldType;
                field.Attributes = classVarModifiers;
                if (varContext.Initializer != null)
                {
                    field.InitExpression = BuildExpression(varContext.Initializer, false);
                    SaveSourceCode(field.InitExpression, varContext.Initializer);
                }
                FillCodeDomDesignerData(field, varContext.Start.Line, varContext.Start.Column);
                // write original source for the attributes
                AddMemberAttributes(field, classVarModifiers, context.Modifiers);
                writeTrivia(field, context);
                SaveSourceCode(field, varContext);
                //
                FieldList[currentContext].Add(field);
            }
            //
        }
Exemplo n.º 2
0
 public override void EnterClassVarList([NotNull] XSharpParser.ClassVarListContext context)
 {
     //
     if (context.DataType != null && currentClass != null)
     {
         var fieldType = BuildDataType(context.DataType);
         //
         foreach (var varContext in context._Var)
         {
             var field = new XCodeMemberField();
             field.Name       = varContext.Id.GetText();
             field.Type       = fieldType;
             field.Attributes = this.classVarModifiers;
             if (varContext.Initializer != null)
             {
                 if (varContext.Initializer is XSharpParser.PrimaryExpressionContext)
                 {
                     XSharpParser.PrimaryContext ctx = ((XSharpParser.PrimaryExpressionContext)varContext.Initializer).Expr;
                     if (ctx is XSharpParser.LiteralExpressionContext)
                     {
                         XSharpParser.LiteralExpressionContext lit = (XSharpParser.LiteralExpressionContext)ctx;
                         field.InitExpression = BuildLiteralValue(lit.Literal);
                     }
                 }
                 else
                 {
                     field.InitExpression = BuildSnippetExpression(varContext.Initializer.GetText());
                 }
             }
             FillCodeDomDesignerData(field, varContext.Start.Line, varContext.Start.Column);
             //
             FieldList[currentClass].Add(field);
         }
         //
     }
 }
 public override void EnterClassVarList([NotNull] XSharpParser.ClassVarListContext context)
 {
     //
     if (context.DataType != null && currentClass != null)
     {
         var fieldType = BuildDataType(context.DataType);
         //
         foreach (var varContext in context._Var)
         {
             var field = new XCodeMemberField();
             field.Name       = varContext.Id.GetText();
             field.Type       = fieldType;
             field.Attributes = this.classVarModifiers;
             if (varContext.Initializer != null)
             {
                 field.InitExpression = BuildExpression(varContext.Initializer, false);
             }
             FillCodeDomDesignerData(field, varContext.Start.Line, varContext.Start.Column);
             //
             FieldList[currentClass].Add(field);
         }
         //
     }
 }