Exemplo n.º 1
0
 public override void EnterLocalvar([NotNull] XSharpParser.LocalvarContext context)
 {
     if (initComponent != null)
     {
         if (context.DataType != null)
         {
             CodeStatementCollection          locals    = new CodeStatementCollection();
             XCodeTypeReference               localType = BuildDataType(context.DataType);
             CodeVariableDeclarationStatement local;
             // Any previous Local ?
             while (LocalDecls.Count > 0)
             {
                 XSharpParser.LocalvarContext tmpContext = LocalDecls.Pop();
                 local = BuildLocalVar(tmpContext, localType);
                 locals.Add(local);
             }
             // Now, manage the current one
             local = BuildLocalVar(context, localType);
             locals.Add(local);
             //
             initComponent.Statements.AddRange(locals);
         }
         else
         {
             // We may have something like
             // LOCAL x,y as string
             // for x, we don't have a DataType, so save it
             LocalDecls.Push(context);
         }
     }
 }
        public override void ExitLocalvar([NotNull] XSharpParser.LocalvarContext context)
        {
            bool isDim       = context.Dim != null;
            bool hasArraySub = context.ArraySub != null;

            if (isDim && !hasArraySub)
            {
                _parseErrors.Add(new ParseErrorData(context.DIM(), ErrorCode.ERR_ArrayInitializerExpected));
            }
            if (!isDim && hasArraySub && _options.Dialect == XSharpDialect.Core)
            {
                _parseErrors.Add(new ParseErrorData(context.ArraySub, ErrorCode.ERR_FeatureNotAvailableInDialect, "Indexed Local", _options.Dialect.ToString()));
            }
        }
Exemplo n.º 3
0
        private CodeVariableDeclarationStatement BuildLocalVar(XSharpParser.LocalvarContext context, XCodeTypeReference localType)
        {
            CodeVariableDeclarationStatement local = new CodeVariableDeclarationStatement();

            local.Name = context.Id.GetCleanText();
            local.Type = localType;
            if (context.Expression != null)
            {
                local.InitExpression = BuildExpression(context.Expression, false);
            }
            var name = local.Name.ToLower();

            if (!_locals.ContainsKey(name))
            {
                _locals.Add(name, findType(localType.BaseType));
            }
            return(local);
        }
        public override void EnterLocalvar([NotNull] XSharpParser.LocalvarContext context)
        {
            try
            {
                if (context.DataType != null)
                {
                    XVariable local;
                    String    localType = context.DataType.GetText();
                    String    localName;
                    // Push to stack so we can manage all contexts in one loop
                    _localDecls.Push(context);

                    while (_localDecls.Count > 0)
                    {
                        XSharpParser.LocalvarContext tmpContext = _localDecls.Pop();
                        localName = tmpContext.Id.GetText();
                        //
                        local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public,
                                              new TextRange(tmpContext), new TextInterval(tmpContext),
                                              localType);
                        local.File    = this._file;
                        local.IsArray = tmpContext.Dim != null;
                        //
                        if (this._currentMethod != null)
                        {
                            this._currentMethod.Locals.Add(local);
                        }
                    }
                }
                else
                {
                    // We may have something like
                    // LOCAL x,y as STRING
                    // for x, we don't have a DataType, so save it
                    _localDecls.Push(context);
                }
            }
            catch (Exception ex)
            {
                Support.Debug("EnterLocalvar : Error Walking {0}, at {1}/{2} : " + ex.Message, this.File.Name, context.Start.Line, context.Start.Column);
            }
        }