コード例 #1
0
ファイル: Statements.cs プロジェクト: edgar-pek/VCDryad
 /// <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;
 }
コード例 #2
0
ファイル: Statements.cs プロジェクト: edgar-pek/VCDryad
        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;
        }
コード例 #3
0
ファイル: Statements.cs プロジェクト: edgar-pek/VCDryad
 internal VccLocalDefinition(VccLocalDeclaration localDeclaration, List<Specifier> specifiers, bool isSpec)
     : base(localDeclaration)
 {
     this.specifiers = specifiers;
       this.isSpec = isSpec;
 }
コード例 #4
0
ファイル: Statements.cs プロジェクト: tupipa/vcc
        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);
        }
コード例 #5
0
ファイル: Statements.cs プロジェクト: tupipa/vcc
 /// <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;
 }
コード例 #6
0
ファイル: Statements.cs プロジェクト: tupipa/vcc
 internal VccLocalDefinition(VccLocalDeclaration localDeclaration, List <Specifier> specifiers, bool isSpec)
     : base(localDeclaration)
 {
     this.specifiers = specifiers;
     this.isSpec     = isSpec;
 }