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); } // } }
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) { XSharpParser.ClassVarListContext current = (XSharpParser.ClassVarListContext)context; // // structure is: /* * classvars : (Attributes=attributes)? (Modifiers=classvarModifiers)? Vars=classVarList eos * ; * * classVarList : Var+=classvar (COMMA Var+=classvar)* (As=(AS | IS) DataType=datatype)? * ; * * classvar : (Dim=DIM)? Id=identifier (LBRKT ArraySub=arraysub RBRKT)? (ASSIGN_OP Initializer=expression)? * ; */ // we want to include the stop position of the datatype in the classvar // so we set the range to the whole classvarlist var parent = context.Parent as XSharpParserRuleContext; int count, currentVar; count = current._Var.Count; currentVar = 0; foreach (var varContext in current._Var) { // var mods = _currentVarStatic ? Modifiers.Static : Modifiers.None; // when many variables then the first one is from the start of the line until the // end of its name, and the others start with the start of their name // the last one finishes at the end of the line currentVar += 1; var start = parent.Start; // LOCAL keyword or GLOBAL keyword var stop = current.Stop; // end of this line (datatype clause) if (currentVar > 1) { start = varContext.Start; } if (currentVar < count) // end at this variable name { stop = varContext.Stop; } var interval = new TextInterval(start.StartIndex, stop.StopIndex); string typeName = current.DataType != null?current.DataType.GetText() : "USUAL"; XTypeMember newClassVar = new XTypeMember(varContext.Id.GetText(), Kind.Field, mods, this._currentVarVisibility, new TextRange(start.Line, start.Column, stop.Line, stop.Column + stop.Text.Length), interval, typeName, _currentVarStatic); newClassVar.File = this._file; newClassVar.IsArray = varContext.Dim != null; // bool bAdd = true; // Suppress classvars generated by errors in the source if (_errors != null) { foreach (var err in _errors) { if (err.Span.Start.Line == newClassVar.Range.StartLine - 1) { bAdd = false; } } } if (bAdd) { this._classVars.Add(newClassVar); } } }