Пример #1
0
        public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations)
        {
            if (localDeclarations == null)
            {
                return(null);
            }
            FieldFlags flags = FieldFlags.CompilerControlled | FieldFlags.NotSerialized; //NotSerialized "poisons" the field until Checker clears it

            if (localDeclarations.Constant)
            {
                flags |= FieldFlags.Literal;
            }
            else if (localDeclarations.InitOnly)
            {
                flags = FieldFlags.Public | FieldFlags.InitOnly;
            }
            TypeNode             type  = localDeclarations.Type;
            LocalDeclarationList decls = localDeclarations.Declarations;

            for (int i = 0, n = decls.Count; i < n; i++)
            {
                LocalDeclaration decl = decls[i];
                Field            f    = new Field(this.scope, null, flags, decl.Name, type, null);
                f.Initializer = this.VisitExpression(decl.InitialValue);
                this.scope.Members.Add(f);
                decl.Field = f;
            }
            return(localDeclarations);
        }
Пример #2
0
 /// <summary>
 /// Makes a copy of this local declaration, changing the ContainingBlock to the given block.
 /// </summary>
 //^ [MustOverride]
 public override LocalDeclaration MakeCopyFor(LocalDeclarationsStatement containingLocalDeclarationsStatement)
 //^^ ensures result.GetType() == this.GetType();
 {
     if (this.ContainingLocalDeclarationsStatement == containingLocalDeclarationsStatement)
     {
         return(this);
     }
     return(new VccLocalDeclaration(containingLocalDeclarationsStatement, this));
 }
Пример #3
0
 //^ [MustOverride]
 public override LocalDeclaration MakeCopyFor(LocalDeclarationsStatement containingLocalDeclarationsStatement)
 {
     if (this.ContainingLocalDeclarationsStatement == containingLocalDeclarationsStatement)
     {
         return(this);
     }
     else
     {
         return(new VccLocalFunctionDeclaration(containingLocalDeclarationsStatement, this));
     }
 }
Пример #4
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations){
   if (localDeclarations == null) return null;
   FieldFlags flags = FieldFlags.CompilerControlled|FieldFlags.NotSerialized; //NotSerialized "poisons" the field until Checker clears it
   if (localDeclarations.Constant) flags |= FieldFlags.Literal;
   else if (localDeclarations.InitOnly) flags = FieldFlags.Public|FieldFlags.InitOnly;
   TypeNode type = localDeclarations.Type;
   LocalDeclarationList decls = localDeclarations.Declarations;
   for (int i = 0, n = decls.Count; i < n; i++){
     LocalDeclaration decl = decls[i];
     Field f = new Field(this.scope, null, flags, decl.Name, type, null);
     f.Initializer = this.VisitExpression(decl.InitialValue);
     this.scope.Members.Add(f);
     decl.Field = f;
   }
   return localDeclarations;
 }
Пример #5
0
        public virtual Statement VisitResourceUse(ResourceUse resourceUse, Class scope)
        {
            if (resourceUse == null)
            {
                return(null);
            }
            Class savedScope = this.scope;

            this.scope = scope;
            LocalDeclarationsStatement locDecs = resourceUse.ResourceAcquisition as LocalDeclarationsStatement;

            if (locDecs != null)
            {
                locDecs.InitOnly = true;
                resourceUse.ResourceAcquisition = this.VisitLocalDeclarationsStatement(locDecs);
            }
            resourceUse.Body = this.VisitBlock(resourceUse.Body);
            this.scope       = savedScope;
            return(resourceUse);
        }
Пример #6
0
        public virtual Statement VisitAcquire(Acquire @acquire, Class scope)
        {
            if (@acquire == null)
            {
                return(null);
            }
            Class savedScope = this.scope;

            this.scope = scope;
            LocalDeclarationsStatement locDecs = @acquire.Target as LocalDeclarationsStatement;

            if (locDecs != null)
            {
                locDecs.InitOnly = true;
                @acquire.Target  = this.VisitLocalDeclarationsStatement(locDecs);
            }
            @acquire.Body = this.VisitBlock(@acquire.Body);
            this.scope    = savedScope;
            return(@acquire);
        }
Пример #7
0
        public virtual Statement VisitFixed(Fixed Fixed, Class scope)
        {
            if (Fixed == null)
            {
                return(null);
            }
            Class savedScope = this.scope;

            this.scope = scope;
            LocalDeclarationsStatement locDecs = Fixed.Declarators as LocalDeclarationsStatement;

            if (locDecs != null)
            {
                locDecs.InitOnly  = true;
                Fixed.Declarators = this.VisitLocalDeclarationsStatement(locDecs);
            }
            Fixed.Body = this.VisitBlock(Fixed.Body);
            this.scope = savedScope;
            return(Fixed);
        }
Пример #8
0
        public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations)
        {
            if (localDeclarations == null)
            {
                return(null);
            }
            TypeNode type = localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type);

            if (!localDeclarations.Constant)
            {
                return(localDeclarations);
            }
            LocalDeclarationList decls = localDeclarations.Declarations;

            for (int i = 0, n = decls.Count; i < n; i++)
            {
                LocalDeclaration decl = decls[i];
                Field            f    = decl.Field;
                f.Type        = type;
                f.Initializer = this.VisitExpression(f.Initializer);
            }
            return(localDeclarations);
        }
Пример #9
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);
        }
Пример #10
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations){
   if (localDeclarations == null) return null;
   TypeNode type = localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type);
   if (!localDeclarations.Constant && !localDeclarations.InitOnly) return localDeclarations;
   LocalDeclarationList decls = localDeclarations.Declarations;
   for (int i = 0, n = decls.Count; i < n; i++){
     LocalDeclaration decl = decls[i];
     Field f = decl.Field;
     if (type != null)
       f.Type = type;
     f.Initializer = decl.InitialValue = this.VisitExpression(f.Initializer);
     Construct c = decl.InitialValue as Construct;
     if (c != null && c.Type == null)
       c.Type = type;
     Identifier id = decl.InitialValue as Identifier;
     if (id != null && id.Type == null && type != null && type.IsAssignableTo(SystemTypes.Enum))
       id.Type = type;
   }
   return localDeclarations;
 }
Пример #11
0
 /// <summary>
 /// A copy constructor that allocates an instance that is the same as the given template, except for its containing block.
 /// </summary>
 /// <param name="containingLocalDeclarationsStatement">The containing statement. This should be different from the containing statement of the template declaration.</param>
 /// <param name="template">The statement to copy.</param>
 protected VccLocalDeclaration(LocalDeclarationsStatement containingLocalDeclarationsStatement, VccLocalDeclaration template)
     : base(containingLocalDeclarationsStatement, template)
 {
     this.specifiers = new List<Specifier>(template.specifiers);
       this.isSpec = template.isSpec;
 }
Пример #12
0
        protected override bool CheckForErrorsAndReturnTrueIfAnyAreFound()
        {
            if (pattern == null)
            return Body.HasErrors;

              var hasError = false;
              var newStmts = new List<Statement>();
              var newBlock = new BlockStatement(newStmts, this.SourceLocation);
              var call = pattern as VccMethodCall;
              if (call == null) {
            this.Helper.ReportError(new VccErrorMessage(pattern.SourceLocation, Error.ExpectedIdentifier));
            return true;
              }

              var args = call.OriginalArguments.ToArray();
              var calledMethod = call.MethodExpression as VccSimpleName;
              if (calledMethod == null) {
            this.Helper.ReportError(new VccErrorMessage(call.MethodExpression.SourceLocation, Error.ExpectedIdentifier));
            return true;
              }

              var methods = call.GetCandidateMethods(true).Where(m => m.ParameterCount == args.Length).ToArray();
              if (methods.Length == 0) {
            if (!call.MethodExpression.HasErrors)
              this.Helper.ReportError(new AstErrorMessage(call, Cci.Ast.Error.BadNumberOfArguments, calledMethod.Name.Value, args.Length.ToString()));
            return true;
              }

              var meth = (MethodDefinition)methods.First();
              var decl = (FunctionDefinition)meth.Declaration;
              var parms = decl.Parameters.ToArray();
              List<Statement> stmts = new List<Statement>();
              for (int i = 0; i < args.Length; ++i) {
            var name = args[i] as VccSimpleName;
            if (name == null) {
              this.Helper.ReportError(new VccErrorMessage(args[i].SourceLocation, Error.ExpectedIdentifier));
              hasError = true;
            } else {
              var local = new VccLocalDeclaration(new NameDeclaration(name.Name, name.SourceLocation), null, new List<Specifier>(), true, name.SourceLocation);
              var tp = (TypeExpression)parms[i].Type;
              //tp = (TypeExpression)tp.MakeCopyFor(newBlock);
              var stmt = new LocalDeclarationsStatement(false, true, false, tp, new LocalDeclaration[] { local }.ToList(), name.SourceLocation);
              newStmts.Add(stmt);
            }
              }

              newStmts.Add(new ExpressionStatement(call));

              if (_body != null)
            newStmts.AddRange(_body.Statements);
              else
            newStmts.AddRange(statements);

              _body = newBlock;
              newBlock.SetContainingBlock(containingMatchStatement.ContainingBlock);
              hasError |= newBlock.HasErrors;

              return hasError;
        }
Пример #13
0
 //^ [MustOverride]
 public override LocalDeclaration MakeCopyFor(LocalDeclarationsStatement containingLocalDeclarationsStatement)
 {
     if (this.ContainingLocalDeclarationsStatement == containingLocalDeclarationsStatement) return this;
       else return new VccLocalFunctionDeclaration(containingLocalDeclarationsStatement, this);
 }
Пример #14
0
 /// <summary>
 /// A copy constructor that allocates an instance that is the same as the given template, except for its containing block.
 /// </summary>
 /// <param name="containingLocalDeclarationsStatement">The containing statement. This should be different from the containing statement of the template declaration.</param>
 /// <param name="template">The statement to copy.</param>
 protected VccLocalFunctionDeclaration(LocalDeclarationsStatement containingLocalDeclarationsStatement, VccLocalFunctionDeclaration template)
     : base(containingLocalDeclarationsStatement, template)
 {
     this.mangledFunctionDeclaration = template.mangledFunctionDeclaration;
 }
Пример #15
0
        protected override bool CheckForErrorsAndReturnTrueIfAnyAreFound()
        {
            if (pattern == null)
            {
                return(Body.HasErrors);
            }

            var hasError = false;
            var newStmts = new List <Statement>();
            var newBlock = new BlockStatement(newStmts, this.SourceLocation);
            var call     = pattern as VccMethodCall;

            if (call == null)
            {
                this.Helper.ReportError(new VccErrorMessage(pattern.SourceLocation, Error.ExpectedIdentifier));
                return(true);
            }

            var args         = call.OriginalArguments.ToArray();
            var calledMethod = call.MethodExpression as VccSimpleName;

            if (calledMethod == null)
            {
                this.Helper.ReportError(new VccErrorMessage(call.MethodExpression.SourceLocation, Error.ExpectedIdentifier));
                return(true);
            }

            var methods = call.GetCandidateMethods(true).Where(m => m.ParameterCount == args.Length).ToArray();

            if (methods.Length == 0)
            {
                if (!call.MethodExpression.HasErrors)
                {
                    this.Helper.ReportError(new AstErrorMessage(call, Cci.Ast.Error.BadNumberOfArguments, calledMethod.Name.Value, args.Length.ToString()));
                }
                return(true);
            }

            var meth  = (MethodDefinition)methods.First();
            var decl  = (FunctionDefinition)meth.Declaration;
            var parms = decl.Parameters.ToArray();
            List <Statement> stmts = new List <Statement>();

            for (int i = 0; i < args.Length; ++i)
            {
                var name = args[i] as VccSimpleName;
                if (name == null)
                {
                    this.Helper.ReportError(new VccErrorMessage(args[i].SourceLocation, Error.ExpectedIdentifier));
                    hasError = true;
                }
                else
                {
                    var local = new VccLocalDeclaration(new NameDeclaration(name.Name, name.SourceLocation), null, new List <Specifier>(), true, name.SourceLocation);
                    var tp    = (TypeExpression)parms[i].Type;
                    //tp = (TypeExpression)tp.MakeCopyFor(newBlock);
                    var stmt = new LocalDeclarationsStatement(false, true, false, tp, new LocalDeclaration[] { local }.ToList(), name.SourceLocation);
                    newStmts.Add(stmt);
                }
            }

            newStmts.Add(new ExpressionStatement(call));

            if (_body != null)
            {
                newStmts.AddRange(_body.Statements);
            }
            else
            {
                newStmts.AddRange(statements);
            }

            _body = newBlock;
            newBlock.SetContainingBlock(containingMatchStatement.ContainingBlock);
            hasError |= newBlock.HasErrors;

            return(hasError);
        }
Пример #16
0
 protected virtual LocalDefinition CreateLocalTempForProjection(List<Statement> statements)
 {
     IName dummyName = this.ContainingBlock.Helper.NameTable.GetNameFor("__temp" + this.SourceLocation.StartIndex);
       NameDeclaration tempName = new NameDeclaration(dummyName, this.SourceLocation);
       LocalDeclaration temp = new LocalDeclaration(false, false, tempName, null, this.SourceLocation);
       List<LocalDeclaration> declarations = new List<LocalDeclaration>(1) {temp};
       LocalDeclarationsStatement statement = new LocalDeclarationsStatement(false, false, false, TypeExpression.For(this.structureTypeExpression.ResolvedType), declarations, this.SourceLocation);
       statements.Add(statement);
       statement.SetContainingBlock(this.ContainingBlock);
       temp.SetContainingLocalDeclarationsStatement(statement);
       return temp.LocalVariable;
 }
Пример #17
0
    public virtual Differences VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations1, LocalDeclarationsStatement localDeclarations2){
      Differences differences = new Differences(localDeclarations1, localDeclarations2);
      if (localDeclarations1 == null || localDeclarations2 == null){
        if (localDeclarations1 != localDeclarations2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      LocalDeclarationsStatement changes = (LocalDeclarationsStatement)localDeclarations2.Clone();
      LocalDeclarationsStatement deletions = (LocalDeclarationsStatement)localDeclarations2.Clone();
      LocalDeclarationsStatement insertions = (LocalDeclarationsStatement)localDeclarations2.Clone();

      if (localDeclarations1.Constant == localDeclarations2.Constant) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      LocalDeclarationList declChanges, declDeletions, declInsertions;
      Differences diff = this.VisitLocalDeclarationList(localDeclarations1.Declarations, localDeclarations2.Declarations, out declChanges, out declDeletions, out declInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Declarations = declChanges;
      deletions.Declarations = declDeletions;
      insertions.Declarations = declInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (localDeclarations1.InitOnly == localDeclarations2.InitOnly) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
      
      diff = this.VisitTypeNode(localDeclarations1.Type, localDeclarations2.Type);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Type = diff.Changes as TypeNode;
      deletions.Type = diff.Deletions as TypeNode;
      insertions.Type = diff.Insertions as TypeNode;
      //Debug.Assert(diff.Changes == changes.Type && diff.Deletions == deletions.Type && diff.Insertions == insertions.Type);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
Пример #18
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations) {
   if (localDeclarations == null) return null;
   localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type);
   return localDeclarations;
 }
Пример #19
0
    //private ParseFixedPointerDeclarations

    private LocalDeclarationsStatement ParseFixedPointerDeclarations(SourceLocationBuilder slb, TypeExpression typeExpression, TokenSet followers)
      //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
    {
      List<LocalDeclaration> declarations = new List<LocalDeclaration>();
      for (; ; ) {
        NameDeclaration locName = this.ParseNameDeclaration();
        SourceLocationBuilder locSctx = new SourceLocationBuilder(locName.SourceLocation);
        if (declarations.Count == 0) locSctx.UpdateToSpan(typeExpression.SourceLocation);
        this.Skip(Token.Assign);
        Expression/*?*/ locInitialValue = this.ParseExpression(followers|Token.Semicolon|Token.Comma);
        locSctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken);
        slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken);
        declarations.Add(new FixedPointerDeclaration(locName, locInitialValue, locSctx));
        if (this.currentToken != Token.Comma) break;
        this.GetNextToken();
      }
      declarations.TrimExcess();
      LocalDeclarationsStatement result = new LocalDeclarationsStatement(false, true, false, typeExpression, declarations, slb);
      this.SkipTo(followers);
      return result;
    }
Пример #20
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations){
   if (localDeclarations == null) return 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) continue;
     decl.InitialValue = null;  // delete the intial value expression so later phases won't get confused in light of comment below.
     Field f = decl.Field;
     if (f == null) continue;
     f.Initializer = this.VisitExpression(f.Initializer);
     //If the method scope is captured for a closure, 
     if (f.Initializer == null && ((BlockScope)f.DeclaringType).CapturedForClosure)
       //Force Normalizer to bind it to the current closure class before any nested closures are visited
       this.VisitMemberBinding(new MemberBinding(new ImplicitThis(), f));
   }
   if (this.currentMethod != null && this.currentMethod.Scope != null && this.currentMethod.Scope.CapturedForClosure) return null;
   return localDeclarations; // leave it for Writer to use for associating debug info
 }    
Пример #21
0
 /// <summary>
 /// A copy constructor that allocates an instance that is the same as the given template, except for its containing block.
 /// </summary>
 /// <param name="containingLocalDeclarationsStatement">The containing statement. This should be different from the containing statement of the template declaration.</param>
 /// <param name="template">The statement to copy.</param>
 protected VccLocalDeclaration(LocalDeclarationsStatement containingLocalDeclarationsStatement, VccLocalDeclaration template)
     : base(containingLocalDeclarationsStatement, template)
 {
     this.specifiers = new List <Specifier>(template.specifiers);
     this.isSpec     = template.isSpec;
 }
Пример #22
0
 public override  Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations){
   if (localDeclarations == null) return null;
   this.AbstractSealedUsedAsType = Error.AbstractSealedLocalType;
   TypeNode type = localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type, true);
   if (type == null){
     TypeExpression texpr = localDeclarations.TypeExpression as TypeExpression;
     if (texpr != null && texpr.ConsolidatedTemplateArguments != null && this.identifierInfos != null &&
       texpr.SourceContext.Document != null && texpr.SourceContext.Document.Text != null && texpr.SourceContext.EndPos == texpr.SourceContext.Document.Text.Length-1) {
       //Could be a call to a generic method.
       TemplateInstance ti = new TemplateInstance(texpr.Expression, texpr.ConsolidatedTemplateArguments);
       ti.SourceContext = texpr.SourceContext;
       ti.IsMethodTemplate = true;
       MethodCall mcall = new MethodCall(ti, new ExpressionList(0));
       mcall.SourceContext = texpr.SourceContext;
       return (Statement)this.Visit(new ExpressionStatement(mcall, mcall.SourceContext));
     }
   }
   this.AbstractSealedUsedAsType = Error.NotAType;
   LocalDeclarationList decls = localDeclarations.Declarations;
   int n = decls.Count;
   if (localDeclarations.Constant || localDeclarations.InitOnly){
     for (int i = 0; i < n; i++){
       LocalDeclaration decl = decls[i];
       if (decl == null) continue;
       decl = this.VisitLocalDeclaration(decl);
       Field f = decl.Field;
       if (f == null) continue;
       f.Type = type;
       f.Initializer = decl.InitialValue = this.VisitExpression(f.Initializer);
     }
     return localDeclarations;
   }else{
     StatementList statements = new StatementList(n+1);
     statements.Add(localDeclarations);
     for (int i = 0; i < n; i++){
       LocalDeclaration decl = decls[i];
       if (decl == null) continue;
       decl = this.VisitLocalDeclaration(decl);
       Field f = decl.Field;
       if (f == null) continue;
       f.Type = type;
       f.Initializer = null;
       MemberBinding mb = new MemberBinding(new ImplicitThis(this.scope, 0), f);
       mb.Type = type;
       mb.SourceContext = decl.Name.SourceContext;
       Expression initVal = decl.InitialValue = this.VisitExpression(decl.InitialValue);
       if (initVal == null) continue;
       AssignmentStatement aStat = new AssignmentStatement(mb, initVal, decl.AssignmentNodeType);
       aStat.SourceContext = localDeclarations.SourceContext;
       if (decl.SourceContext.Document != null) {
         aStat.SourceContext = decl.SourceContext;
         Debug.Assert(aStat.SourceContext.EndPos >= aStat.SourceContext.StartPos);
       }
       statements.Add(aStat);
     }
     Block b = new Block(statements);
     b.SourceContext = localDeclarations.SourceContext;
     return b;
   }
 }
Пример #23
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations){
   if (localDeclarations == null) return null;
   this.VisitResolvedTypeReference(localDeclarations.Type, localDeclarations.TypeExpression);
   return base.VisitLocalDeclarationsStatement(localDeclarations);
 }
Пример #24
0
 public virtual Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations, LocalDeclarationsStatement changes, LocalDeclarationsStatement deletions, LocalDeclarationsStatement insertions){
   this.UpdateSourceContext(localDeclarations, changes);
   if (localDeclarations == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return localDeclarations;
 }
Пример #25
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations){
   if (localDeclarations == null) return null;
   TypeNode type = localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type);
   if (!localDeclarations.Constant) return localDeclarations;
   LocalDeclarationList decls = localDeclarations.Declarations;
   for (int i = 0, n = decls.Count; i < n; i++){
     LocalDeclaration decl = decls[i];
     Field f = decl.Field;
     f.Type = type;
     f.Initializer = this.VisitExpression(f.Initializer);
   }
   return localDeclarations;
 }    
Пример #26
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations) {
   return localDeclarations;
 }
Пример #27
0
    private LocalDeclarationsStatement ParseLocalDeclarations(SourceLocationBuilder slb, TypeExpression typeExpression, bool constant, bool initOnly, bool skipSemicolon, TokenSet followers)
      //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
    {
      List<LocalDeclaration> declarations = new List<LocalDeclaration>();
      for (; ; ) {
        NameDeclaration locName = this.ParseNameDeclaration();
        SourceLocationBuilder locSctx = new SourceLocationBuilder(locName.SourceLocation);
        //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 
        Expression/*?*/ locInitialValue = null;
        if (this.currentToken == Token.Assign || constant) {
          this.Skip(Token.Assign);
          ArrayTypeExpression/*?*/ arrayTypeExpression = typeExpression as ArrayTypeExpression;
          if (this.currentToken == Token.LeftBrace && arrayTypeExpression != null)
            locInitialValue = this.ParseArrayInitializer(arrayTypeExpression, followers|Token.Semicolon|Token.Comma);
          else
            locInitialValue = this.ParseExpression(followers|Token.Semicolon|Token.Comma);
        }
        locSctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken);
        if (declarations.Count == 0) locSctx.UpdateToSpan(typeExpression.SourceLocation);
        slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken);
        declarations.Add(new LocalDeclaration(false, false, locName, locInitialValue, locSctx));

        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 (skipSemicolon) this.SkipSemiColon(followers);
      declarations.TrimExcess();
      LocalDeclarationsStatement result = new LocalDeclarationsStatement(constant, initOnly, !constant, typeExpression, declarations, slb);
      this.SkipTo(followers);
      return result;
    }
Пример #28
0
 /// <summary>
 /// A copy constructor that allocates an instance that is the same as the given template, except for its containing block.
 /// </summary>
 /// <param name="containingLocalDeclarationsStatement">The containing statement. This should be different from the containing statement of the template declaration.</param>
 /// <param name="template">The statement to copy.</param>
 protected VccLocalFunctionDeclaration(LocalDeclarationsStatement containingLocalDeclarationsStatement, VccLocalFunctionDeclaration template)
     : base(containingLocalDeclarationsStatement, template)
 {
     this.mangledFunctionDeclaration = template.mangledFunctionDeclaration;
 }
Пример #29
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations) {
   if (localDeclarations == null) return null;
   TypeNode type = localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type);
   TypeNode unwrappedType = this.typeSystem.Unwrap(type);
   LocalDeclarationList decls = localDeclarations.Declarations;
   Pointer declaredPointerType = unwrappedType as Pointer;
   if (this.insideFixedDeclarator && declaredPointerType == null) {
     this.HandleError(localDeclarations.TypeExpression, Error.BadFixedVariableType);
     return null;
   }
   for (int i = 0, n = decls.Count; i < n; i++) {
     LocalDeclaration decl = decls[i];
     if (decl == null) continue;
     Field f = decl.Field;
     if (f == null) continue;
     f.Flags &= ~FieldFlags.NotSerialized; //Remove this flag so that subsequent references are OK
     if (type != null)
       f.Type = type;
     if (this.requireInitializer && f.Initializer == null)
       this.HandleError(decl.Name, Error.FixedMustInit);
     else if (this.insideFixedDeclarator && f.Initializer != null && f.Initializer.NodeType == NodeType.ExplicitCoercion)
       this.HandleError(decl, Error.BadExplicitCoercionInFixed);
     f.Initializer = this.VisitExpression(f.Initializer);
     if (f.Initializer == null || f.Initializer.Type == null) continue;
     if (this.insideFixedDeclarator && declaredPointerType != null && f.IsInitOnly) {
       Expression source = f.Initializer;
       TypeNode unwrappedSource = this.typeSystem.Unwrap(source.Type);
       ArrayType arrType = unwrappedSource as ArrayType;
       if (arrType != null && arrType.ElementType != null) {
         Indexer indexer = new Indexer(source, new ExpressionList(Literal.Int32Zero), arrType.ElementType, source.SourceContext);
         indexer.ArgumentListIsIncomplete = true;
         source = new UnaryExpression(indexer, NodeType.AddressOf, indexer.Type.GetReferenceType(), source.SourceContext);
       } else if (unwrappedSource == SystemTypes.String && declaredPointerType.ElementType == SystemTypes.Char) {
         f.Initializer = this.typeSystem.ImplicitCoercion(source, unwrappedSource, this.TypeViewer);
         continue;
       }
       f.Initializer = this.typeSystem.ImplicitCoercion(source, declaredPointerType, this.TypeViewer);
       continue;
     }
     if (!localDeclarations.Constant) continue;
     if (!(f.Initializer is Literal) /*&& !(f.Initializer is AnonymousNestedFunction)*/) {
       this.HandleError(f.Name, Error.NotConstantExpression, f.Name.ToString());
       decls[i] = null;
     }
     Literal lit = f.Initializer as Literal;
     if (lit != null)
       f.Initializer = this.VisitExpression(this.typeSystem.ImplicitLiteralCoercion(lit, lit.Type, f.Type, this.TypeViewer));
   }
   return localDeclarations;
 }
Пример #30
0
 public virtual Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations1, LocalDeclarationsStatement localDeclarations2)
 {
     if (localDeclarations1 == null) return null;
     if (localDeclarations2 == null)
     {
         localDeclarations1.Type = this.VisitTypeReference(localDeclarations1.Type, null);
         localDeclarations1.Declarations = this.VisitLocalDeclarationList(localDeclarations1.Declarations, null);
     }
     else
     {
         localDeclarations1.Type = this.VisitTypeReference(localDeclarations1.Type, localDeclarations2.Type);
         localDeclarations1.Declarations = this.VisitLocalDeclarationList(localDeclarations1.Declarations, localDeclarations2.Declarations);
     }
     return localDeclarations1;
 }
Пример #31
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;
 }
Пример #32
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations)
 {
     if (localDeclarations == null) return null;
     return base.VisitLocalDeclarationsStatement((LocalDeclarationsStatement)localDeclarations.Clone());
 }
Пример #33
0
        public static void report(Node node, int shift)
        {
            if (node == null)
            {
                indent(shift);
                Console.WriteLine("NULL ENTITY");
                return;
            }

            switch (node.NodeType)
            {
            case NodeType.AliasDefinition:
            {
                AliasDefinition alias = node as AliasDefinition;
                indent(shift);
                Console.WriteLine("using {0} = {1};", alias.Alias.Name, alias.AliasedUri.Name);
                break;
            }

            case NodeType.CompilationUnit:
            case NodeType.CompilationUnitSnippet:
            {
                CompilationUnit cu = node as CompilationUnit;

                for (int i = 0, n = cu.Nodes.Length; i < n; i++)
                {
                    report(cu.Nodes[i], 0);
                }
                break;
            }

            case NodeType.Namespace:
            {
                Namespace ns = node as Namespace;

                if (ns.UsedNamespaces != null && ns.UsedNamespaces.Length != 0)
                {
                    indent(shift);
                    Console.WriteLine("using ");
                    for (int i = 0, n = ns.UsedNamespaces.Length; i < n; i++)
                    {
                        Console.Write("{0}", ns.UsedNamespaces[i].Namespace.Name);
                        if (i < n - 1)
                        {
                            Console.Write(", ");
                        }
                    }
                    Console.WriteLine();
                }

                indent(shift);
                Console.WriteLine("namespace {0}", ns.FullNameId.Name);

                indent(shift);
                Console.WriteLine("{");

                if (ns.AliasDefinitions != null && ns.AliasDefinitions.Length != 0)
                {
                    for (int i = 0, n = ns.AliasDefinitions.Length; i < n; i++)
                    {
                        report(ns.AliasDefinitions[i], shift + ind);
                    }
                }

                if (ns.NestedNamespaces != null && ns.NestedNamespaces.Length != 0)
                {
                    for (int i = 0, n = ns.NestedNamespaces.Length; i < n; i++)
                    {
                        report(ns.NestedNamespaces[i], shift + ind);
                    }
                }

                if (ns.Types != null && ns.Types.Length != 0)
                {
                    for (int i = 0, n = ns.Types.Length; i < n; i++)
                    {
                        report(ns.Types[i], shift + ind);
                    }
                }

                indent(shift);
                Console.WriteLine("}");

                break;
            }

            case NodeType.Class:
            {
                Class cls = node as Class;

                if (cls == SystemTypes.Object)
                {
                    Console.Write(cls.Name);
                    break;
                }

                indent(shift);

                if (cls.IsAbstract)
                {
                    Console.Write("abstract ");
                }
                if (cls.IsPrivate)
                {
                    Console.Write("private ");
                }
                else if (cls.IsPublic)
                {
                    Console.Write("public ");
                }
                else
                {
                    Console.Write("internal ");                             // ??????????????
                }
                if (cls.IsSealed)
                {
                    Console.Write("sealed ");
                }

                Console.Write("class ");
                if (cls.DeclaringType != null)
                {
                    Console.Write("{0}::", cls.DeclaringType.Name.Name);
                }
                Console.Write("{0}", cls.Name != null?cls.Name.Name:"<NONAME>");

                if (cls.BaseClass != null)
                {
                    Console.Write(" : {0}", cls.BaseClass.Name.Name);
                }

                if (cls.Interfaces != null && cls.Interfaces.Length != 0)
                {
                    if (cls.BaseClass != null)
                    {
                        Console.Write(",");
                    }
                    else
                    {
                        Console.Write(" :");
                    }

                    for (int i = 0, n = cls.Interfaces.Length; i < n; i++)
                    {
                        Interface interfac = cls.Interfaces[i];
                        if (interfac != null)
                        {
                            Console.Write(" {0}", interfac.Name.Name);
                        }
                        if (i < n - 1)
                        {
                            Console.Write(",");
                        }
                    }
                }
                Console.WriteLine();

                indent(shift);
                Console.WriteLine("{");

                if (cls.Members != null && cls.Members.Length != 0)
                {
                    for (int i = 0, n = cls.Members.Length; i < n; i++)
                    {
                        Member member = cls.Members[i];

                        if (member == null)
                        {
                            indent(shift + ind);
                            Console.WriteLine("<UNRESOLVED MEMBER>");
                            continue;
                        }
                        report(member, shift + ind);
                    }
                }
                indent(shift);
                Console.WriteLine("}");

                break;
            }

            case NodeType.Struct:
            {
                Struct struc = node as Struct;

                indent(shift);

                if (struc.IsAbstract)
                {
                    Console.Write("abstract ");
                }
                if (struc.IsPrivate)
                {
                    Console.Write("private ");
                }
                else if (struc.IsPublic)
                {
                    Console.Write("public ");
                }
                else
                {
                    Console.Write("internal ");                               // ??????????????
                }
                if (struc.IsSealed)
                {
                    Console.Write("sealed ");
                }

                Console.Write("struct ");
                if (struc.DeclaringType != null)
                {
                    Console.Write("{0}::", struc.DeclaringType.Name.Name);
                }
                Console.Write("{0}", struc.Name != null?struc.Name.Name:"<NONAME>");

                if (struc.Interfaces != null && struc.Interfaces.Length != 0)
                {
                    Console.Write(" :");
                    for (int i = 0, n = struc.Interfaces.Length; i < n; i++)
                    {
                        Interface interfac = struc.Interfaces[i];
                        if (interfac != null)
                        {
                            Console.Write(" {0}", interfac.Name.Name);
                        }
                        if (i < n - 1)
                        {
                            Console.Write(",");
                        }
                    }
                }
                Console.WriteLine();

                indent(shift);
                Console.WriteLine("{");

                if (struc.Members != null && struc.Members.Length != 0)
                {
                    for (int i = 0, n = struc.Members.Length; i < n; i++)
                    {
                        Member member = struc.Members[i];

                        if (member == null)
                        {
                            indent(shift + ind);
                            Console.WriteLine("<UNRESOLVED MEMBER>");
                            continue;
                        }
                        report(member, shift + ind);
                    }
                }
                indent(shift);
                Console.WriteLine("}");
                break;
            }

            case NodeType.EnumNode:
            {
                EnumNode enume = node as EnumNode;

                indent(shift);
                if (enume.Name != null && enume.Name.Name != null)
                {
                    Console.Write("enum {0} = ", enume.Name.Name);
                }
                else
                {
                    Console.Write("enum <NONAME> = ");
                }
                Console.Write("{");

                for (int i = 0, n = enume.Members.Length; i < n; i++)
                {
                    Field enumerator = (Field)enume.Members[i];
                    Console.Write("{0}", enumerator.Name.Name);
                    if (enumerator.DefaultValue != null)
                    {
                        Console.Write(" = {0}", enumerator.DefaultValue.ToString());
                    }
                    if (i < n - 1)
                    {
                        Console.Write(", ");
                    }
                }
                Console.WriteLine("};");

                break;
            }

            case NodeType.Interface:
            {
                Interface interfac = node as Interface;

                indent(shift);

                if (interfac.IsAbstract)
                {
                    Console.Write("abstract ");
                }
                if (interfac.IsPrivate)
                {
                    Console.Write("private ");
                }
                else if (interfac.IsPublic)
                {
                    Console.Write("public ");
                }
                else
                {
                    Console.Write("internal ");                                // ???????????
                }
                Console.WriteLine("interface {0}", interfac.Name.Name);
                indent(shift);
                Console.WriteLine("{");

                if (interfac.Members != null && interfac.Members.Length != 0)
                {
                    for (int i = 0, n = interfac.Members.Length; i < n; i++)
                    {
                        Member member = interfac.Members[i];

                        if (member == null)
                        {
                            indent(shift + ind);
                            Console.WriteLine("<UNRESOLVED MEMBER>");
                            continue;
                        }
                        report(member, shift + ind);
                    }
                }
                indent(shift);
                Console.WriteLine("}");

                break;
            }

            case NodeType.Method:
            case NodeType.InstanceInitializer:
            {
                Method method = node as Method;

                indent(shift);

                if (method.IsAbstract)
                {
                    Console.Write("abstract ");
                }
                if (method.IsPublic)
                {
                    Console.Write("public ");
                }
                if (method.IsStatic)
                {
                    Console.Write("static ");
                }
                if (method.IsVirtual)
                {
                    Console.Write("virtual ");
                }
                if (method.IsPrivate)
                {
                    Console.Write("private ");
                }
                if (method.OverriddenMethod != null)
                {
                    Console.Write("override ");
                }

                if (method.ReturnType != null && method.ReturnType.Name != null)
                {
                    Console.Write("{0} ", method.ReturnType.Name.Name);
                }
                if (method.Name != null)
                {
                    if (method.ImplementedInterfaceMethods != null && method.ImplementedInterfaceMethods.Length != 0)
                    {
                        Method interf = method.ImplementedInterfaceMethods[0];
                        if (interf != null)
                        {
                            string name = interf.DeclaringType.Name.Name;
                            Console.Write("{0}.", name);
                        }
                    }
                    Console.Write("{0}", method.Name.Name);
                }
                Console.Write(" (");

                if (method.Parameters != null && method.Parameters.Length != 0)
                {
                    for (int i = 0, n = method.Parameters.Length; i < n; i++)
                    {
                        Parameter par = method.Parameters[i];
                        if (par == null)
                        {
                            continue;
                        }
                        if ((par.Flags & ParameterFlags.In) != 0)
                        {
                            Console.Write("in ");
                        }
                        if ((par.Flags & ParameterFlags.Out) != 0)
                        {
                            Console.Write("out ");
                        }

                        if (par.Type != null && par.Type.Name != null)
                        {
                            Console.Write("{0}", par.Type.Name.Name);
                        }
                        else
                        {
                            report(par.Type, 0);
                        }
                        Console.Write(" {0}", par.Name.Name);
                        if (i < n - 1)
                        {
                            Console.Write(", ");
                        }
                    }
                }
                Console.Write(" )");

                // method body
                if (method.Body != null)
                {
                    Console.WriteLine();
                    report(method.Body, shift);
                }
                else
                {
                    Console.WriteLine(";");
                }
                break;
            }

            case NodeType.DelegateNode:
            {
                DelegateNode dn = node as DelegateNode;

                indent(shift);
                Console.Write("delegate ");

                if (dn.ReturnType != null && dn.ReturnType.Name != null)
                {
                    Console.Write("{0} ", dn.ReturnType.Name.Name);
                }
                if (dn.Name != null)
                {
                    Console.Write("{0}", dn.Name.Name);
                }
                Console.Write(" (");

                if (dn.Parameters != null && dn.Parameters.Length != 0)
                {
                    for (int i = 0, n = dn.Parameters.Length; i < n; i++)
                    {
                        Parameter par = dn.Parameters[i];
                        if (par == null)
                        {
                            continue;
                        }
                        if ((par.Flags & ParameterFlags.In) != 0)
                        {
                            Console.Write("in ");
                        }
                        if ((par.Flags & ParameterFlags.Out) != 0)
                        {
                            Console.Write("out ");
                        }

                        if (par.Type != null && par.Type.Name != null)
                        {
                            Console.Write("{0}", par.Type.Name.Name);
                        }
                        else
                        {
                            report(par.Type, 0);
                        }
                        Console.Write(" {0}", par.Name.Name);
                        if (i < n - 1)
                        {
                            Console.Write(", ");
                        }
                    }
                }
                Console.WriteLine(" );");
                break;
            }

            case NodeType.StaticInitializer:
            {
                StaticInitializer si = node as StaticInitializer;

                indent(shift);

                Console.WriteLine("static {0} ( )", si.Name.Name);

                // body
                if (si.Body != null)
                {
                    report(si.Body, shift);
                }
                else
                {
                    Console.WriteLine("NO BODY");
                }
                break;
            }

            case NodeType.FieldInitializerBlock:
            {
                FieldInitializerBlock initializers = node as FieldInitializerBlock;

                indent(shift);
                if (initializers.IsStatic)
                {
                    Console.Write("static ");
                }
                Console.WriteLine("init {");
                for (int i = 0, n = initializers.Statements.Length; i < n; i++)
                {
                    report(initializers.Statements[i], shift + ind);
                }
                indent(shift);
                Console.WriteLine("}");
                break;
            }

            case NodeType.Base:
            {
                Console.Write("base");
                break;
            }

            case NodeType.Field:
            {
                Field field = node as Field;

                indent(shift);

                if (field.IsPrivate)
                {
                    Console.Write("private ");
                }
                else if (field.IsPublic)
                {
                    Console.Write("public ");
                }

                if (field.IsStatic)
                {
                    Console.Write("static ");
                }
                if (field.IsInitOnly)
                {
                    Console.Write("readonly ");
                }

                if (field.Type != null)
                {
                    if (field.Type.Name != null)
                    {
                        Console.Write("{0}", field.Type.Name.Name);
                    }
                    else
                    {
                        report(field.Type, 0);
                    }
                }
                Console.Write(" {0}", field.Name.Name);

                if (field.Initializer != null)
                {
                    Console.Write(" = ");
                    report(field.Initializer, 0);
                }
                Console.WriteLine(";");

                break;
            }

            case NodeType.VariableDeclaration:
            {
                VariableDeclaration variable = node as VariableDeclaration;

                indent(shift);
                if (variable.Type != null && variable.Type.Name != null)
                {
                    Console.Write("{0}", variable.Type.Name.Name);
                }
                else
                {
                    report(variable.Type, 0);
                }

                Console.Write(" {0}", variable.Name.Name);

                if (variable.Initializer != null)
                {
                    Console.Write(" = ");
                    report(variable.Initializer, 0);
                }
                Console.WriteLine(";");

                break;
            }

            case NodeType.LocalDeclarationsStatement:
            {
                LocalDeclarationsStatement stmt = node as LocalDeclarationsStatement;

                indent(shift);

                TypeNode type = stmt.Type;
                if (type != null && type.Name != null)
                {
                    Console.Write("{0}", type.Name.Name);
                }
                else
                {
                    report(type, 0);
                }
                Console.Write(" ");

                LocalDeclarationList list = stmt.Declarations;
                for (int i = 0, n = list.Length; i < n; i++)
                {
                    LocalDeclaration local = list[i];
                    Console.Write("{0}", local.Name.Name);
                    if (local.InitialValue != null)
                    {
                        Console.Write(" = ");
                        report(local.InitialValue, 0);
                    }
                    if (i < n - 1)
                    {
                        Console.Write(", ");
                    }
                }
                Console.WriteLine(";");
                break;
            }

            case NodeType.Property:
            {
                Property property = node as Property;

                indent(shift);

                if (property.IsPrivate)
                {
                    Console.Write("private ");
                }
                else if (property.IsPublic)
                {
                    Console.Write("public ");
                }

                if (property.IsStatic)
                {
                    Console.Write("static ");
                }

                if (property != null)
                {
                    if (property.Type != null && property.Type.Name != null)
                    {
                        Console.Write("{0} ", property.Type.Name.Name);
                    }

                    if (property.ImplementedTypes != null)
                    {
                        TypeNode typ = property.ImplementedTypes[0];
                        Console.Write("{0}.", typ.Name.Name);
                    }
                    if (property.Name != null)
                    {
                        Console.WriteLine("{0}", property.Name.Name);
                    }
                }
                indent(shift);
                Console.WriteLine("{");

                if (property.Getter != null)
                {
                    report(property.Getter, shift + ind);
                }
                if (property.Setter != null)
                {
                    report(property.Setter, shift + ind);
                }

                indent(shift);
                Console.WriteLine("}");

                break;
            }

            case NodeType.Lock:
            {
                Lock _lock = node as Lock;

                indent(shift);
                Console.Write("lock(");
                report(_lock.Guard, shift);
                Console.WriteLine(")");
                report(_lock.Body, shift + ind);
                indent(shift);
                Console.WriteLine("}");

                break;
            }

            case NodeType.Block:
            {
                Block block = node as Block;
                if (block == null || block.Statements == null)
                {
                    break;
                }
                indent(shift);
                Console.WriteLine("{");

                for (int i = 0, n = block.Statements.Length; i < n; i++)
                {
                    report(block.Statements[i], shift + ind);
                    Console.WriteLine();
                }
                indent(shift);
                Console.WriteLine("}");

                break;
            }

            case NodeType.MemberBinding:
            {
                MemberBinding mb = node as MemberBinding;
                if (mb.TargetObject != null)
                {
                    report(mb.TargetObject, 0);
                }
                else if (mb.BoundMember != null && mb.BoundMember.DeclaringType != null)
                {
                    Console.Write(mb.BoundMember.DeclaringType.Name);
                }
                Console.Write(".");
                if (mb.BoundMember.Name != null)
                {
                    Console.Write(mb.BoundMember.Name.Name);
                }
                else
                {
                    report(mb.BoundMember, 0);
                }
                break;
            }

            case NodeType.AssignmentStatement:
            {
                AssignmentStatement assignment = node as AssignmentStatement;

                indent(shift);

                report(assignment.Target, 0);
                switch (assignment.Operator)
                {
                case NodeType.Nop: Console.Write(" = "); break;

                case NodeType.Add: Console.Write(" += "); break;

                case NodeType.Add_Ovf: Console.Write(" += "); break;

                case NodeType.Add_Ovf_Un: Console.Write(" += "); break;

                case NodeType.Sub: Console.Write(" -= "); break;

                case NodeType.Sub_Ovf: Console.Write(" -= "); break;

                case NodeType.Sub_Ovf_Un: Console.Write(" -= "); break;

                case NodeType.Mul: Console.Write(" *= "); break;

                case NodeType.Mul_Ovf: Console.Write(" *= "); break;

                case NodeType.Mul_Ovf_Un: Console.Write(" *= "); break;
                }
                report(assignment.Source, 0);
                Console.Write(";");
                break;
            }

            case NodeType.ExpressionStatement:
            {
                ExpressionStatement exprStatement = node as ExpressionStatement;

                indent(shift);

                report(exprStatement.Expression, 0);
                Console.Write(";");
                break;
            }

            case NodeType.Return:
            {
                Return return_stmt = node as Return;

                indent(shift);
                Console.Write("return");
                if (return_stmt.Expression != null)
                {
                    Console.Write(" ");
                    report(return_stmt.Expression, 0);
                }
                Console.Write(";");

                break;
            }

            case NodeType.Branch:
            {
                Branch branch = node as Branch;

                indent(shift);
                Console.WriteLine("break; (???)");

                break;
            }

            case NodeType.For:
            {
                For for_stmt = node as For;

                indent(shift);
                Console.Write("for ( ");
                for (int i = 0, n = for_stmt.Initializer.Length; i < n; i++)
                {
                    report(for_stmt.Initializer[i], 0);
                }
                report(for_stmt.Condition, 0);
                Console.Write("; ");
                for (int i = 0, n = for_stmt.Incrementer.Length; i < n; i++)
                {
                    report(for_stmt.Incrementer[i], 0);
                }
                Console.WriteLine(")");

                indent(shift);
                Console.WriteLine("{");
                report(for_stmt.Body, shift + ind);
                indent(shift);
                Console.WriteLine("}");

                break;
            }

            case NodeType.While:
            {
                While while_loop = node as While;

                indent(shift);
                Console.Write("while ( ");
                report(while_loop.Condition, 0);
                Console.WriteLine(" )");

                report(while_loop.Body, shift);

                break;
            }

            case NodeType.DoWhile:
            {
                DoWhile repeat = node as DoWhile;

                indent(shift);
                Console.WriteLine("do");
                report(repeat.Body, shift);

                indent(shift);
                Console.Write("while (");
                report(repeat.Condition, 0);
                Console.WriteLine(" );");

                break;
            }

            case NodeType.If:
            {
                If if_stmt = node as If;

                indent(shift);
                Console.Write("if ( ");
                report(if_stmt.Condition, 0);
                Console.WriteLine(" )");

                report(if_stmt.TrueBlock, shift);

                if (if_stmt.FalseBlock == null ||
                    if_stmt.FalseBlock.Statements == null ||
                    if_stmt.FalseBlock.Statements.Length == 0)
                {
                    break;
                }

                indent(shift);
                Console.WriteLine("else");
                report(if_stmt.FalseBlock, shift);

                break;
            }

            case NodeType.Switch:
            {
                Switch swtch = node as Switch;

                indent(shift);
                Console.Write("switch ( ");
                report(swtch.Expression, 0);
                Console.WriteLine(" )");

                indent(shift);
                Console.WriteLine("{");

                for (int i = 0, n = swtch.Cases.Length; i < n; i++)
                {
                    indent(shift + ind);
                    if (swtch.Cases[i].Label != null)
                    {
                        Console.Write("case ");
                        report(swtch.Cases[i].Label, 0);
                        Console.WriteLine(":");
                    }
                    else
                    {
                        Console.WriteLine("default:");
                    }
                    report(swtch.Cases[i].Body, shift + ind);
                }
                indent(shift);
                Console.WriteLine("}");

                break;
            }

            case NodeType.Throw:
            {
                Throw thro = node as Throw;

                indent(shift);
                Console.Write("throw (");
                report(thro.Expression, 0);
                Console.Write(");");
                break;
            }

            case NodeType.Exit:
            {
                indent(shift);
                Console.WriteLine("exit;");
                break;
            }

            case NodeType.Continue:
            {
                indent(shift);
                Console.WriteLine("continue;");
                break;
            }

            case NodeType.Try:
            {
                Try trys = node as Try;

                indent(shift);
                Console.WriteLine("try {");
                report(trys.TryBlock, shift + ind);
                indent(shift);
                Console.WriteLine("}");
                if (trys.Catchers != null)
                {
                    for (int i = 0, n = trys.Catchers.Length; i < n; i++)
                    {
                        indent(shift);
                        if (trys.Catchers[i].Type != null)
                        {
                            Console.Write("catch ( {0} ", trys.Catchers[i].Type.FullName);
                        }
                        else
                        {
                            Console.Write("catch ( ");
                        }
                        if (trys.Catchers[i].Variable != null)
                        {
                            report(trys.Catchers[i].Variable, 0);
                        }
                        Console.WriteLine(" ) {");
                        report(trys.Catchers[i].Block, shift + ind);
                        indent(shift);
                        Console.WriteLine("}");
                    }
                }
                if (trys.Finally != null && trys.Finally.Block != null)
                {
                    indent(shift);
                    Console.WriteLine("finally");
                    report(trys.Finally.Block, shift);
                }
                break;
            }

            case NodeType.BlockExpression:
            {
                BlockExpression be = node as BlockExpression;

                Console.WriteLine("(");
                StatementList sl = be.Block.Statements;
                for (int i = 0, n = sl.Length; i < n; i++)
                {
                    report(sl[i], shift + ind);
                }
                indent(shift);
                Console.Write(")");
                break;
            }

            case NodeType.ArrayTypeExpression:
            {
                ArrayTypeExpression array = node as ArrayTypeExpression;

                indent(shift);

                if (array.ElementType != null &&
                    array.ElementType.Name != null &&
                    array.ElementType.Name.Name != null)
                {
                    Console.Write(array.ElementType.Name.Name);
                }
                else
                {
                    report(array.ElementType, 0);
                }

                Console.Write("[");
                for (int i = 0, n = array.Rank; i < n; i++)
                {
                    if (array.Sizes != null)
                    {
                        Console.Write(array.Sizes[i]);
                    }
                    if (i < n - 1)
                    {
                        Console.Write(",");
                    }
                }
                Console.Write("]");

                break;
            }

            case NodeType.Construct:
            {
                Construct construct = node as Construct;

                indent(shift);
                Console.Write("new ");
                report(construct.Constructor, 0);
                Console.Write("(");
                if (construct.Operands != null)
                {
                    for (int i = 0, n = construct.Operands.Length; i < n; i++)
                    {
                        report(construct.Operands[i], 0);
                        if (i < n - 1)
                        {
                            Console.Write(",");
                        }
                    }
                }
                Console.Write(")");
                break;
            }

            case NodeType.ConstructArray:
            {
                ConstructArray initializer = node as ConstructArray;

                Console.Write("new ");

                if (initializer.ElementType != null &&
                    initializer.ElementType.Name != null &&
                    initializer.ElementType.Name.Name != null)
                {
                    Console.Write(initializer.ElementType.Name.Name);
                }
                else
                {
                    report(initializer.ElementType, 0);
                }

                Console.Write("[");
                for (int i = 0, n = initializer.Operands.Length; i < n; i++)
                {
                    report(initializer.Operands[i], 0);
                    if (i < n - 1)
                    {
                        Console.Write(",");
                    }
                }
                Console.Write("]");

                break;
            }

            case NodeType.ConstructDelegate:
            {
                ConstructDelegate cd = node as ConstructDelegate;

                // Console.Write("new {0}({1})",cd.DelegateType.Name.Name,cd.MethodName.Name);
                Console.Write("new {0}(", cd.DelegateType.Name.Name);
                report(cd.TargetObject, 0);
                Console.Write(".{0})", cd.MethodName.Name);
                // cd.Type;
                break;
            }

            default:
            {
                if (node is ZonnonCompilation)
                {
                    ZonnonCompilation zc = node as ZonnonCompilation;
                    report(zc.CompilationUnits[0], shift);
                }
                // Expression?

                else if (node is MethodCall)
                {
                    MethodCall call = node as MethodCall;

                    report(call.Callee, 0);
                    Console.Write("(");

                    if (call.Operands != null && call.Operands.Length != 0)
                    {
                        for (int i = 0, n = call.Operands.Length; i < n; i++)
                        {
                            report(call.Operands[i], 0);
                            if (i < n - 1)
                            {
                                Console.Write(",");
                            }
                        }
                    }

                    Console.Write(")");
                }
                else if (node is Variable)
                {
                    Variable variable = node as Variable;
                    Console.Write("{0}", variable.Name.Name);
                }
                else if (node is Identifier)
                {
                    Identifier identifier = node as Identifier;
                    Console.Write("{0}", identifier.Name);
                }
                else if (node is QualifiedIdentifier)
                {
                    QualifiedIdentifier qualid = node as QualifiedIdentifier;
                    report(qualid.Qualifier, 0);
                    Console.Write(".{0}", qualid.Identifier == null?"<UNRESOLVED>":qualid.Identifier.Name);
                }
                else if (node is Literal)
                {
                    Literal literal = node as Literal;
                    if (literal.Value == null)
                    {
                        Console.Write("null");
                    }
                    else
                    {
                        if (literal.Value is string)
                        {
                            Console.Write("\"");
                        }
                        else if (literal.Value is char)
                        {
                            Console.Write("'");
                        }
                        Console.Write("{0}", literal.Value.ToString());
                        if (literal.Value is string)
                        {
                            Console.Write("\"");
                        }
                        else if (literal.Value is char)
                        {
                            Console.Write("'");
                        }
                    }
                }
                else if (node is Indexer)
                {
                    Indexer indexer = node as Indexer;
                    report(indexer.Object, 0);
                    Console.Write("[");
                    for (int i = 0, n = indexer.Operands.Length; i < n; i++)
                    {
                        report(indexer.Operands[i], 0);
                        if (i < n - 1)
                        {
                            Console.Write(",");
                        }
                    }
                    Console.Write("]");
                }
                else if (node is UnaryExpression)
                {
                    UnaryExpression unexpr = node as UnaryExpression;

                    bool add_pars = unexpr.Operand is BinaryExpression ||
                                    unexpr.Operand is UnaryExpression;

                    switch (unexpr.NodeType)
                    {
                    case NodeType.Add: Console.Write("+");  break;

                    case NodeType.Sub: Console.Write("-");  break;

                    case NodeType.Neg: Console.Write("-");  break;

                    case NodeType.Not: Console.Write("~");  break;

                    case NodeType.UnaryPlus: Console.Write("+"); break;

                    case NodeType.LogicalNot: Console.Write("!"); break;

                    case NodeType.Conv_U2: Console.Write("(UInt16)"); break;

                    case NodeType.RefAddress: Console.Write("ref "); break;

                    case NodeType.Ckfinite: Console.Write("(Ckfinite)"); break;

                    default:           Console.Write("???");  break;
                    }

                    if (add_pars)
                    {
                        Console.Write("(");
                    }
                    report(unexpr.Operand, 0);
                    if (add_pars)
                    {
                        Console.Write(")");
                    }
                }
                else if (node is BinaryExpression)
                {
                    BinaryExpression binexpr = node as BinaryExpression;

                    bool add_pars = binexpr.Operand1 is BinaryExpression ||
                                    binexpr.Operand1 is UnaryExpression;

                    if (binexpr.NodeType == NodeType.Castclass)
                    {
                        Console.Write("(");
                        report(binexpr.Operand2, 0);
                        Console.Write(")");

                        if (add_pars)
                        {
                            Console.Write("(");
                        }
                        report(binexpr.Operand1, 0);
                        if (add_pars)
                        {
                            Console.Write(")");
                        }
                        break;
                    }

                    if (add_pars)
                    {
                        Console.Write("(");
                    }
                    report(binexpr.Operand1, 0);
                    if (add_pars)
                    {
                        Console.Write(")");
                    }

                    switch (binexpr.NodeType)
                    {
                    case NodeType.Add: Console.Write(" + "); break;

                    case NodeType.Add_Ovf: Console.Write(" + "); break;

                    case NodeType.Add_Ovf_Un: Console.Write(" + "); break;

                    case NodeType.Sub: Console.Write(" - "); break;

                    case NodeType.Sub_Ovf: Console.Write(" - "); break;

                    case NodeType.Sub_Ovf_Un: Console.Write(" - "); break;

                    case NodeType.Mul: Console.Write(" * "); break;

                    case NodeType.Mul_Ovf: Console.Write(" * "); break;

                    case NodeType.Mul_Ovf_Un: Console.Write(" * "); break;

                    case NodeType.Div: Console.Write(" / "); break;

                    // case NodeType.Div : Console.Write(" DIV "); break;  // "DIV" ?????
                    case NodeType.Rem: Console.Write(" % "); break;          // "MOD" ?????

                    case NodeType.Or: Console.Write(" | "); break;

                    case NodeType.And: Console.Write(" & "); break;

                    case NodeType.Eq: Console.Write(" == "); break;

                    case NodeType.Ne: Console.Write(" != "); break;

                    case NodeType.Lt: Console.Write(" < "); break;

                    case NodeType.Le: Console.Write(" <= "); break;

                    case NodeType.Gt: Console.Write(" > "); break;

                    case NodeType.Ge: Console.Write(" >= "); break;

                    case NodeType.LogicalOr: Console.Write(" || "); break;

                    case NodeType.LogicalAnd: Console.Write(" && "); break;

                    case NodeType.Is: Console.Write(" is "); break;

                    case NodeType.Comma: Console.Write(","); break;

                    // case OPERATORS.In           : expression.NodeType = NodeType  // "IN" break;
                    // case OPERATORS.Implements   : expression.NodeType = NodeType  // "IMPLEMENTS" break;
                    default: Console.Write(" !! "); break;
                    }

                    add_pars = binexpr.Operand2 is BinaryExpression ||
                               binexpr.Operand2 is UnaryExpression;

                    if (add_pars)
                    {
                        Console.Write("(");
                    }
                    report(binexpr.Operand2, 0);
                    if (add_pars)
                    {
                        Console.Write(")");
                    }
                }
                else if (node is TernaryExpression)
                {
                    TernaryExpression ter = node as TernaryExpression;
                    if (ter.NodeType == NodeType.Conditional)
                    {
                        report(ter.Operand1, 0);
                        Console.Write(" ? ");
                        report(ter.Operand2, 0);
                        Console.Write(" : ");
                        report(ter.Operand3, 0);
                    }
                }
                else if (node is PostfixExpression)
                {
                    PostfixExpression postfixExpr = node as PostfixExpression;

                    report(postfixExpr.Expression, 0);

                    switch (postfixExpr.Operator)
                    {
                    case NodeType.Increment: Console.Write("++"); break;

                    case NodeType.Decrement: Console.Write("--"); break;

                    default: Console.Write("???"); break;
                    }
                }
                else if (node is LabeledStatement)
                {
                    LabeledStatement lbst = node as LabeledStatement;
                    indent(shift);
                    report(lbst.Label, 0);
                    Console.Write(" : ");
                    report(lbst.Statement, 0);
                }
                else if (node is Goto)
                {
                    Goto gt = node as Goto;
                    indent(shift);
                    Console.Write("goto ");
                    report(gt.TargetLabel, 0);
                }
                else
                {
                    indent(shift);
                    Console.WriteLine("No code for reporting {0}:{1}", node.UniqueKey, node.ToString());
                }
                break;
            }
            }
        }
Пример #34
0
 public virtual void VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations)
 {
   if (localDeclarations == null) return;
   this.VisitTypeReference(localDeclarations.Type);
   this.VisitLocalDeclarationList(localDeclarations.Declarations);
 }
Пример #35
0
 public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations)
 {
     return(localDeclarations);
 }
Пример #36
0
        public static Method GetArrayInitializationMethod(String name, bool isPublic, TypeNode declaringType, ARRAY_TYPE type, SourceContext sourceContext)
        {
            //Array NewTypeName()
            //{
            //    Array Res;
            //    Res = new Array[A.GetLength(0), A.GetLength(1)];
            //    for (int i1 = 0; i1 < A.GetLength(0); i1++)
            //        Res[i1] = new Array[];
            //    return Res;
            //}

            TypeNode returnType = (TypeNode)type.convertAndGetType();
            Method   method     = new Method();

            method.Name          = Identifier.For("New" + name);
            method.DeclaringType = declaringType;
            method.Flags         = MethodFlags.Static;
            if (isPublic)
            {
                method.Flags |= MethodFlags.Public;
            }
            else
            {
                method.Flags |= MethodFlags.Private;
            }
            method.InitLocals      = true;
            method.SourceContext   = sourceContext;
            method.Body            = new Block();
            method.Body.Checked    = false; //???
            method.Body.HasLocals  = true;
            method.Body.Statements = new StatementList();

            method.ReturnType = returnType;

            method.Parameters = new ParameterList();
            int count = 0;
            // Add parameters
            List <Expression> parameterAccess = new List <Expression>();
            ARRAY_TYPE        arrayType       = type;

            while (arrayType != null)
            {
                for (int i = 0; i < arrayType.dimensions.Length; i++)
                {
                    if (arrayType.dimensions[i] == null || arrayType.dimensions[i].calculate() == null)
                    {
                        Identifier paramName = Identifier.For("n" + count.ToString());
                        Parameter  parameter = new Parameter(paramName, SystemTypes.Int32);
                        method.Parameters.Add(parameter);
                        parameterAccess.Add(paramName);
                        count++;
                    }
                }
                if (arrayType.base_type is ARRAY_TYPE)
                {
                    arrayType = (ARRAY_TYPE)arrayType.base_type;
                }
                else
                {
                    arrayType = null;
                }
            }

            Identifier resultName = Identifier.For("res");

            LocalDeclarationsStatement loc_stmt = new LocalDeclarationsStatement();

            loc_stmt.Constant      = false;
            loc_stmt.Declarations  = new LocalDeclarationList(1);
            loc_stmt.InitOnly      = false;
            loc_stmt.SourceContext = sourceContext;
            loc_stmt.Type          = returnType;

            LocalDeclaration local = new LocalDeclaration();

            local.Name          = resultName;
            local.SourceContext = sourceContext;
            loc_stmt.Declarations.Add(local);

            method.Body.Statements.Add(loc_stmt);

            method.Body.Statements.Add(createElementInitializerInternal(type, resultName, 0, parameterAccess, false, sourceContext));

            Return ret = new Return();

            ret.Expression = resultName;

            method.Body.Statements.Add(ret);
            return(method);
        }