Exemple #1
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;
 }
Exemple #2
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;
        }
Exemple #3
0
 internal VccLocalDefinition(VccLocalDeclaration localDeclaration, List<Specifier> specifiers, bool isSpec)
     : base(localDeclaration)
 {
     this.specifiers = specifiers;
       this.isSpec = isSpec;
 }
Exemple #4
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);
        }
Exemple #5
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;
 }
Exemple #6
0
 internal VccLocalDefinition(VccLocalDeclaration localDeclaration, List <Specifier> specifiers, bool isSpec)
     : base(localDeclaration)
 {
     this.specifiers = specifiers;
     this.isSpec     = isSpec;
 }