Ejemplo n.º 1
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations) {
   if (localDeclarations == null) return null;
   Statement result = base.VisitLocalDeclarationsStatement(localDeclarations);
   if (localDeclarations.Type == null && localDeclarations.TypeExpression is TypeExpression) {
     Identifier id = ((TypeExpression)localDeclarations.TypeExpression).Expression as Identifier;
     if (id != null && id.UniqueIdKey == StandardIds.Var.UniqueIdKey) {
       //Use the inferred type of the initializer of the first declaration as the variable type
       TypeNode t = null;
       LocalDeclarationList decls = localDeclarations.Declarations;
       for (int i = 0, n = decls == null ? 0 : decls.Count; i < n; i++) {
         LocalDeclaration decl = decls[i];
         if (decl == null || decl.Field == null) continue;
         if (t == null) {
           if (decl.InitialValue != null)
             t = decl.InitialValue.Type;
         }
         decl.Field.Type = t;
         localDeclarations.Type = t;
       }
     }
   }
   return result;
 }
Ejemplo n.º 2
0
 public virtual Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations)
 {
     if (localDeclarations == null) return null;
     localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type);
     localDeclarations.Declarations = this.VisitLocalDeclarationList(localDeclarations.Declarations);
     return localDeclarations;
 }
Ejemplo n.º 3
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations)
 {
     if (localDeclarations == null) return null;
     return base.VisitLocalDeclarationsStatement((LocalDeclarationsStatement)localDeclarations.Clone());
 }
Ejemplo n.º 4
0
 private Statement ParseLocalDeclarations(TypeNode t, SourceContext ctx, bool constant, bool initOnly, bool preferExpressionToDeclaration, bool skipSemicolon, TokenSet followers){
   TypeNode firstT = t;
   LocalDeclarationsStatement result = new LocalDeclarationsStatement();
   result.SourceContext = ctx;
   result.Constant = constant;
   result.InitOnly = initOnly;
   ScannerState oss = this.scanner.state;
   LocalDeclarationList locList = result.Declarations = new LocalDeclarationList();
   result.Type = result.TypeExpression = t;
   for(;;){
     LocalDeclaration loc = new LocalDeclaration();
     loc.SourceContext = this.scanner.CurrentSourceContext;
     locList.Add(loc);
     loc.Name = this.scanner.GetIdentifier();
     this.SkipIdentifierOrNonReservedKeyword();
     if (this.currentToken == Token.LeftBracket){
       this.HandleError(Error.CStyleArray);
       int endPos = this.scanner.endPos;
       int rank = this.ParseRankSpecifier(true, followers|Token.RightBracket|Parser.IdentifierOrNonReservedKeyword|Token.Assign|Token.Semicolon|Token.Comma);
       if (rank > 0)
         t = result.Type = result.TypeExpression =
           this.ParseArrayType(rank, t, followers|Token.RightBracket|Parser.IdentifierOrNonReservedKeyword|Token.Assign|Token.Semicolon|Token.Comma);
       else{
         this.currentToken = Token.LeftBracket;
         this.scanner.endPos = endPos;
         this.GetNextToken();
         while (!this.scanner.TokenIsFirstAfterLineBreak &&
           this.currentToken != Token.RightBracket && this.currentToken != Token.Assign && this.currentToken != Token.Semicolon)
           this.GetNextToken();
         if (this.currentToken == Token.RightBracket) this.GetNextToken();
       }
     }
     if (this.currentToken == Token.LeftParenthesis){
       this.HandleError(Error.BadVarDecl);
       int dummy;
       SourceContext lpCtx = this.scanner.CurrentSourceContext;
       this.GetNextToken();
       this.ParseArgumentList(followers|Token.LeftBrace|Token.Semicolon|Token.Comma, lpCtx, out dummy);
     }else if (this.currentToken == Token.Assign || constant){
       this.Skip(Token.Assign);
       if (this.currentToken == Token.LeftBrace)
         loc.InitialValue = this.ParseArrayInitializer(t, followers|Token.Semicolon|Token.Comma);
       else
         loc.InitialValue = this.ParseExpression(followers|Token.Semicolon|Token.Comma);
     }
     if (loc.InitialValue != null)
       loc.SourceContext.EndPos = loc.InitialValue.SourceContext.EndPos;
     else
       loc.SourceContext.EndPos = this.scanner.endPos;
     if (this.currentToken != Token.Comma) break;
     this.GetNextToken();
     SourceContext sctx = this.scanner.CurrentSourceContext;
     ScannerState ss = this.scanner.state;
     TypeNode ty = this.ParseTypeExpression(null, followers|Token.Identifier|Token.Comma|Token.Semicolon, true);
     if (ty == null || this.currentToken != Token.Identifier){
       this.scanner.endPos = sctx.StartPos;
       this.scanner.state = ss;
       this.currentToken = Token.None;
       this.GetNextToken();
     }else
       this.HandleError(sctx, Error.MultiTypeInDeclaration);
   }
   if (Parser.IsVoidType(firstT)){
     this.HandleError(ctx, Error.NoVoidHere);
     result.Type = this.TypeExpressionFor(Token.Object);
     result.Type.SourceContext = firstT.SourceContext;
   }
   if (preferExpressionToDeclaration && this.currentToken != Token.Semicolon && locList.Count == 1 && locList[0].InitialValue == null){
     //The parse as a declaration is going to fail. Since an expression is preferred, restore the state and reparse as an expression
     this.scanner.endPos = ctx.StartPos;
     this.scanner.state = oss;
     this.currentToken = Token.None;
     this.GetNextToken();
     ExpressionStatement eStat = new ExpressionStatement(this.ParseExpression(followers));
     if (eStat.Expression != null) eStat.SourceContext = eStat.Expression.SourceContext;
     return eStat;
   }
   if (skipSemicolon) this.SkipSemiColon(followers);
   this.SkipTo(followers);
   return result;
 }
Ejemplo n.º 5
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations) {
   // This node just represents the declaration of a local, e.g., "int x;"
   // No code is generated for it; it is passed in post-normalized code just
   // so the Writer can use it to associate debug info with the block containing
   // the declaration.
   return null;
 }
Ejemplo n.º 6
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations)
 {
     if (localDeclarations == null) return null;
     localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type);
     LocalDeclarationList decls = localDeclarations.Declarations;
     if (decls != null)
     {
         int n = decls.Count;
         LocalDeclarationList newDecls = localDeclarations.Declarations = new LocalDeclarationList(n);
         for (int i = 0; i < n; i++)
             newDecls.Add(this.VisitLocalDeclaration(decls[i]));
     }
     return localDeclarations;
 }
Ejemplo n.º 7
0
        public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDecls)
        {
            if (localDecls.Constant)
                WriteStart("const ");
            else
                WriteStart(string.Empty);

            this.VisitTypeReference(localDecls.Type);
            Write(" ");
            this.VisitLocalDeclarationList(localDecls.Declarations);
            WriteFinish(";");

            return localDecls;
        }
Ejemplo n.º 8
0
 public EventingVisitor(Action<LocalDeclarationsStatement> visitLocalDeclarationsStatement) { VisitedLocalDeclarationsStatement += visitLocalDeclarationsStatement; } public event Action<LocalDeclarationsStatement> VisitedLocalDeclarationsStatement; public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations) { if (VisitedLocalDeclarationsStatement != null) VisitedLocalDeclarationsStatement(localDeclarations); return base.VisitLocalDeclarationsStatement(localDeclarations); }