Example #1
0
 private ConstructArray/*!*/ ParseNewArray() {
   TypeNode type = (TypeNode)this.GetMemberFromToken();
   ExpressionList sizes = new ExpressionList(1);
   sizes.Add(PopOperand());
   ConstructArray result = new ConstructArray(type, sizes, null);
   result.Type = type.GetArrayType(1);
   return result;
 }
Example #2
0
    private Method MakeRequiresWithExceptionMethod(string name)
    {
      Parameter conditionParameter = new Parameter(Identifier.For("condition"), SystemTypes.Boolean);
      Parameter messageParameter = new Parameter(Identifier.For("msg"), SystemTypes.String);
      Parameter conditionTextParameter = new Parameter(Identifier.For("conditionTxt"), SystemTypes.String);
      MethodClassParameter typeArg = new MethodClassParameter();
      ParameterList pl = new ParameterList(conditionParameter, messageParameter, conditionTextParameter);

      Block body = new Block(new StatementList());
      Method m = new Method(this.RuntimeContractType, null, Identifier.For(name), pl, SystemTypes.Void, body);
      m.Flags = MethodFlags.Assembly | MethodFlags.Static;
      m.Attributes = new AttributeList();
      m.TemplateParameters = new TypeNodeList(typeArg);
      m.IsGeneric = true;
      this.RuntimeContractType.Members.Add(m);

      typeArg.Name = Identifier.For("TException");
      typeArg.DeclaringMember = m;
      typeArg.BaseClass = SystemTypes.Exception;
      typeArg.ParameterListIndex = 0;
      typeArg.DeclaringModule = this.RuntimeContractType.DeclaringModule;

      Block returnBlock = new Block(new StatementList(new Return()));

      Block b = new Block(new StatementList());
      b.Statements.Add(new Branch(conditionParameter, returnBlock));
      //
      // Generate the following
      //

      // // message == null means: yes we handled it. Otherwise it is the localized failure message
      // var message = RaiseFailureEvent(ContractFailureKind.Precondition, userMessage, conditionString, null);
      // #if assertOnFailure
      // if (message != null) {
      //   Assert(false, message);
      // }
      // #endif

      var messageLocal = new Local(Identifier.For("msg"), SystemTypes.String);
      
      ExpressionList elist = new ExpressionList();
      elist.Add(this.PreconditionKind);
      elist.Add(messageParameter);
      elist.Add(conditionTextParameter);
      elist.Add(Literal.Null);
      b.Statements.Add(new AssignmentStatement(messageLocal, new MethodCall(new MemberBinding(null, this.RaiseFailureEventMethod), elist)));

      if (this.AssertOnFailure)
      {
        var assertMethod = GetSystemDiagnosticsAssertMethod();
        if (assertMethod != null)
        {
          var skipAssert = new Block();
          b.Statements.Add(new Branch(new UnaryExpression(messageLocal, NodeType.LogicalNot), skipAssert));
          // emit assert call
          ExpressionList assertelist = new ExpressionList();
          assertelist.Add(Literal.False);
          assertelist.Add(messageLocal);
          b.Statements.Add(new ExpressionStatement(new MethodCall(new MemberBinding(null, assertMethod), assertelist)));
          b.Statements.Add(skipAssert);
        }
      }
      // // construct exception
      // Exception obj = null;
      // ConstructorInfo ci = typeof(TException).GetConstructor(new[] { typeof(string), typeof(string) });
      // if (ci != null)
      // {
      //   if (reflection.firstArgName == "paramName") {
      //     exceptionObject = ci.Invoke(new[] { userMessage, message }) as Exception;
      //   }
      //   else {
      //     exceptionObject = ci.Invoke(new[] { message, userMessage }) as Exception;
      //   }
      // }
      // else {
      //   ci = typeof(TException).GetConstructor(new[] { typeof(string) });
      //   if (ci != null)
      //   {
      //     exceptionObject = ci.Invoke(new[] { message }) as Exception;
      //   }
      // }
      var exceptionLocal = new Local(Identifier.For("obj"), SystemTypes.Exception);
      b.Statements.Add(new AssignmentStatement(exceptionLocal, Literal.Null));
      var constructorInfoType = TypeNode.GetTypeNode(typeof(System.Reflection.ConstructorInfo));
      Contract.Assume(constructorInfoType != null);
      var methodBaseType = TypeNode.GetTypeNode(typeof(System.Reflection.MethodBase));
      Contract.Assume(methodBaseType != null);
      var constructorLocal = new Local(Identifier.For("ci"), constructorInfoType);
      Contract.Assume(SystemTypes.Type != null);
      var getConstructorMethod = SystemTypes.Type.GetMethod(Identifier.For("GetConstructor"), SystemTypes.Type.GetArrayType(1));
      var typeofExceptionArg = GetTypeFromHandleExpression(typeArg);
      var typeofString = GetTypeFromHandleExpression(SystemTypes.String);
      var typeArrayLocal = new Local(Identifier.For("typeArray"), SystemTypes.Type.GetArrayType(1));
      var typeArray2 = new ConstructArray();
      typeArray2.ElementType = SystemTypes.Type;
      typeArray2.Rank = 1;
      typeArray2.Operands = new ExpressionList(Literal.Int32Two);
      var typeArrayInit2 = new Block(new StatementList());
      typeArrayInit2.Statements.Add(new AssignmentStatement(typeArrayLocal, typeArray2));
      typeArrayInit2.Statements.Add(new AssignmentStatement(new Indexer(typeArrayLocal, new ExpressionList(Literal.Int32Zero), SystemTypes.Type), typeofString));
      typeArrayInit2.Statements.Add(new AssignmentStatement(new Indexer(typeArrayLocal, new ExpressionList(Literal.Int32One), SystemTypes.Type), typeofString));
      typeArrayInit2.Statements.Add(new ExpressionStatement(typeArrayLocal));
      var typeArrayExpression2 = new BlockExpression(typeArrayInit2);
      b.Statements.Add(new AssignmentStatement(constructorLocal, new MethodCall(new MemberBinding(typeofExceptionArg, getConstructorMethod), new ExpressionList(typeArrayExpression2))));
      var elseBlock = new Block();
      b.Statements.Add(new Branch(new UnaryExpression(constructorLocal, NodeType.LogicalNot), elseBlock));
      var endifBlock2 = new Block();

      var invokeMethod = constructorInfoType.GetMethod(Identifier.For("Invoke"), SystemTypes.Object.GetArrayType(1));
      var argArray2 = new ConstructArray();
      argArray2.ElementType = SystemTypes.Object;
      argArray2.Rank = 1;
      argArray2.Operands = new ExpressionList(Literal.Int32Two);
      var argArrayLocal = new Local(Identifier.For("argArray"), SystemTypes.Object.GetArrayType(1));

      var parameterInfoType = TypeNode.GetTypeNode(typeof(System.Reflection.ParameterInfo));
      Contract.Assume(parameterInfoType != null);
      var parametersMethod = methodBaseType.GetMethod(Identifier.For("GetParameters"));
      var get_NameMethod = parameterInfoType.GetMethod(Identifier.For("get_Name"));
      var string_op_EqualityMethod = SystemTypes.String.GetMethod(Identifier.For("op_Equality"), SystemTypes.String, SystemTypes.String);
      var elseArgMsgBlock = new Block();
      var endIfArgMsgBlock = new Block();
      b.Statements.Add(new Branch(new UnaryExpression(new MethodCall(new MemberBinding(null, string_op_EqualityMethod), new ExpressionList(new MethodCall(new MemberBinding(new Indexer(new MethodCall(new MemberBinding(constructorLocal, parametersMethod), new ExpressionList(), NodeType.Callvirt), new ExpressionList(Literal.Int32Zero), parameterInfoType), get_NameMethod), new ExpressionList(), NodeType.Callvirt), new Literal("paramName", SystemTypes.String))), NodeType.LogicalNot), elseArgMsgBlock));

      var argArrayInit2 = new Block(new StatementList());
      argArrayInit2.Statements.Add(new AssignmentStatement(argArrayLocal, argArray2));
      argArrayInit2.Statements.Add(new AssignmentStatement(new Indexer(argArrayLocal, new ExpressionList(Literal.Int32Zero), SystemTypes.Object), messageParameter));
      argArrayInit2.Statements.Add(new AssignmentStatement(new Indexer(argArrayLocal, new ExpressionList(Literal.Int32One), SystemTypes.Object), messageLocal));
      argArrayInit2.Statements.Add(new ExpressionStatement(argArrayLocal));
      var argArrayExpression2 = new BlockExpression(argArrayInit2);
      b.Statements.Add(new AssignmentStatement(exceptionLocal, new BinaryExpression(new MethodCall(new MemberBinding(constructorLocal, invokeMethod), new ExpressionList(argArrayExpression2)), new Literal(SystemTypes.Exception), NodeType.Isinst)));
      b.Statements.Add(new Branch(null, endIfArgMsgBlock));
 
      b.Statements.Add(elseArgMsgBlock);
      var argArrayInit2_1 = new Block(new StatementList());
      argArrayInit2_1.Statements.Add(new AssignmentStatement(argArrayLocal, argArray2));
      argArrayInit2_1.Statements.Add(new AssignmentStatement(new Indexer(argArrayLocal, new ExpressionList(Literal.Int32Zero), SystemTypes.Object), messageLocal));
      argArrayInit2_1.Statements.Add(new AssignmentStatement(new Indexer(argArrayLocal, new ExpressionList(Literal.Int32One), SystemTypes.Object), messageParameter));
      argArrayInit2_1.Statements.Add(new ExpressionStatement(argArrayLocal));
      var argArrayExpression2_1 = new BlockExpression(argArrayInit2_1);
      b.Statements.Add(new AssignmentStatement(exceptionLocal, new BinaryExpression(new MethodCall(new MemberBinding(constructorLocal, invokeMethod), new ExpressionList(argArrayExpression2_1)), new Literal(SystemTypes.Exception), NodeType.Isinst)));

      b.Statements.Add(endIfArgMsgBlock);

      b.Statements.Add(new Branch(null, endifBlock2));

      b.Statements.Add(elseBlock);
      var typeArray1 = new ConstructArray();
      typeArray1.ElementType = SystemTypes.Type;
      typeArray1.Rank = 1;
      typeArray1.Operands = new ExpressionList(Literal.Int32One);
      var typeArrayInit1 = new Block(new StatementList());
      typeArrayInit1.Statements.Add(new AssignmentStatement(typeArrayLocal, typeArray1));
      typeArrayInit1.Statements.Add(new AssignmentStatement(new Indexer(typeArrayLocal, new ExpressionList(Literal.Int32Zero), SystemTypes.Type), typeofString));
      typeArrayInit1.Statements.Add(new ExpressionStatement(typeArrayLocal));
      var typeArrayExpression1 = new BlockExpression(typeArrayInit1);
      b.Statements.Add(new AssignmentStatement(constructorLocal, new MethodCall(new MemberBinding(typeofExceptionArg, getConstructorMethod), new ExpressionList(typeArrayExpression1))));

      b.Statements.Add(new Branch(new UnaryExpression(constructorLocal, NodeType.LogicalNot), endifBlock2));
      var argArray1 = new ConstructArray();
      argArray1.ElementType = SystemTypes.Object;
      argArray1.Rank = 1;
      argArray1.Operands = new ExpressionList(Literal.Int32One);
      var argArrayInit1 = new Block(new StatementList());
      argArrayInit1.Statements.Add(new AssignmentStatement(argArrayLocal, argArray1));
      argArrayInit1.Statements.Add(new AssignmentStatement(new Indexer(argArrayLocal, new ExpressionList(Literal.Int32Zero), SystemTypes.Object), messageLocal));
      argArrayInit1.Statements.Add(new ExpressionStatement(argArrayLocal));
      var argArrayExpression1 = new BlockExpression(argArrayInit1);
      b.Statements.Add(new AssignmentStatement(exceptionLocal, new BinaryExpression(new MethodCall(new MemberBinding(constructorLocal, invokeMethod), new ExpressionList(argArrayExpression1)), new Literal(SystemTypes.Exception), NodeType.Isinst)));

      b.Statements.Add(endifBlock2);

      // // throw it
      // if (exceptionObject == null)
      // {
      //   throw new ArgumentException(displayMessage, message);
      // }
      // else
      // {
      //   throw exceptionObject;
      // }
      var thenBlock3 = new Block();

      b.Statements.Add(new Branch(exceptionLocal, thenBlock3));
      b.Statements.Add(new Throw(new Construct(new MemberBinding(null, SystemTypes.ArgumentException.GetConstructor(SystemTypes.String, SystemTypes.String)), new ExpressionList(messageLocal, messageParameter))));
      b.Statements.Add(thenBlock3);
      b.Statements.Add(new Throw(exceptionLocal));
      b.Statements.Add(returnBlock);
      Contract.Assume(body.Statements != null);
      body.Statements.Add(b);

      Member constructor = null;
      AttributeNode attribute = null;

      #region Add [DebuggerNonUserCodeAttribute]
      if (this.HideFromDebugger) {
        TypeNode debuggerNonUserCode = SystemTypes.SystemAssembly.GetType(Identifier.For("System.Diagnostics"), Identifier.For("DebuggerNonUserCodeAttribute"));
        if (debuggerNonUserCode != null)
        {
            constructor = debuggerNonUserCode.GetConstructor();
            attribute = new AttributeNode(new MemberBinding(null, constructor), null, AttributeTargets.Method);
            m.Attributes.Add(attribute);
        }
      }
      #endregion Add [DebuggerNonUserCodeAttribute]

      TypeNode reliabilityContract = SystemTypes.SystemAssembly.GetType(Identifier.For("System.Runtime.ConstrainedExecution"), Identifier.For("ReliabilityContractAttribute"));
      TypeNode consistency = SystemTypes.SystemAssembly.GetType(Identifier.For("System.Runtime.ConstrainedExecution"), Identifier.For("Consistency"));
      TypeNode cer = SystemTypes.SystemAssembly.GetType(Identifier.For("System.Runtime.ConstrainedExecution"), Identifier.For("Cer"));
      if (reliabilityContract != null && consistency != null && cer != null)
      {
          constructor = reliabilityContract.GetConstructor(consistency, cer);
          if (constructor != null)
          {
              attribute = new AttributeNode(
                new MemberBinding(null, constructor),
                new ExpressionList(
                  new Literal(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, consistency),
                  new Literal(System.Runtime.ConstrainedExecution.Cer.MayFail, cer)),
                  AttributeTargets.Method
                  );
              m.Attributes.Add(attribute);
          }
      }
      return m;
    }
Example #3
0
 public virtual Expression VisitConstructArray(ConstructArray consArr)
 {
     if (consArr == null) return null;
     consArr.ElementType = this.VisitTypeReference(consArr.ElementType);
     consArr.Operands = this.VisitExpressionList(consArr.Operands);
     consArr.Initializers = this.VisitExpressionList(consArr.Initializers);
     consArr.Owner = this.VisitExpression(consArr.Owner);
     return consArr;
 }
Example #4
0
 private ExpressionList ParseArrayInitializer(int rank, TypeNode elementType, TokenSet followers, bool doNotSkipClosingBrace){
   Debug.Assert(this.currentToken == Token.LeftBrace);
   this.GetNextToken();
   ExpressionList initialValues = new ExpressionList();
   if (this.currentToken == Token.RightBrace){
     this.GetNextToken();
     return initialValues;
   }
   for(;;){
     if (rank > 1){
       ConstructArray elemArr = new ConstructArray();
       elemArr.ElementType = elemArr.ElementTypeExpression = elementType;
       elemArr.Rank = rank-1;
       initialValues.Add(elemArr);
       if (this.currentToken == Token.LeftBrace)
         elemArr.Initializers = this.ParseArrayInitializer(rank-1, elementType, followers|Token.Comma|Token.LeftBrace);
       else
         this.SkipTo(followers|Token.Comma|Token.LeftBrace, Error.ExpectedLeftBrace);
     }else{
       if (this.currentToken == Token.LeftBrace){
         this.HandleError(Error.ArrayInitInBadPlace);
         ConstructArray elemArr = new ConstructArray();
         elemArr.ElementType = elemArr.ElementTypeExpression = elementType;
         elemArr.Rank = 1;
         initialValues.Add(elemArr);
         elemArr.Initializers = this.ParseArrayInitializer(1, elementType, followers|Token.Comma|Token.LeftBrace);
       }else
         initialValues.Add(this.ParseExpression(followers|Token.Comma|Token.RightBrace));
     }
     if (this.currentToken != Token.Comma) break;
     this.GetNextToken();
     if (this.currentToken == Token.RightBrace) break;
   }
   if (doNotSkipClosingBrace) return null;
   this.Skip(Token.RightBrace);
   this.SkipTo(followers);
   return initialValues;
 }
Example #5
0
 public override Expression VisitConstructArray(ConstructArray consArr)
 {
     if (consArr == null) return null;
     return base.VisitConstructArray((ConstructArray)consArr.Clone());
 }
Example #6
0
 private Expression ParseNewImplicitlyTypedArray(SourceContext ctx, TokenSet followers) {
   Debug.Assert(this.currentToken == Token.RightBracket);
   ctx.EndPos = this.scanner.endPos;
   this.Skip(Token.RightBracket);
   ConstructArray consArr = new ConstructArray();
   consArr.SourceContext = ctx;
   consArr.Rank = 1;
   if (this.currentToken == Token.LeftBrace)
     consArr.Initializers = this.ParseArrayInitializer(1, null, followers);
   else
     this.Skip(Token.LeftBrace);
   this.SkipTo(followers);
   return consArr;
 }
Example #7
0
 private Expression ParseArrayInitializer(TypeNode type, TokenSet followers){
   NonNullableTypeExpression nnte = type as NonNullableTypeExpression;
   if (nnte != null) type = nnte.ElementType;
   NullableTypeExpression nute = type as NullableTypeExpression;
   if (nute != null) type = nute.ElementType;
   ArrayTypeExpression aType = type as ArrayTypeExpression;
   if (aType != null){
     ConstructArray consArr = new ConstructArray();
     consArr.SourceContext = this.scanner.CurrentSourceContext;
     consArr.ElementType = consArr.ElementTypeExpression = aType.ElementType;
     consArr.Rank = aType.Rank;
     consArr.Initializers = this.ParseArrayInitializer(aType.Rank, aType.ElementType, followers);
     consArr.SourceContext.EndPos = this.scanner.endPos;
     return consArr;
   }
   object savedArrayInitializerOpeningContext = this.arrayInitializerOpeningContext;
   this.arrayInitializerOpeningContext = this.scanner.CurrentSourceContext;
   Expression e = this.ParseBlockExpression(ScannerState.Code, this.scanner.CurrentSourceContext, followers);
   this.arrayInitializerOpeningContext = savedArrayInitializerOpeningContext;
   return e;
 }
Example #8
0
    //HS D
    private Expression ParseCommaSeparetedIdentifierSet() {
	this.Skip(Token.LeftBrace);
	ExpressionList identifiers = new ExpressionList();
	if (this.currentToken != Token.RightBrace){
	    identifiers.Add(new Literal(this.ParsePrefixedIdentifier().ToString())); //FIXME
	    while (this.currentToken == Token.Comma){	    
		this.GetNextToken();
		identifiers.Add(new Literal(this.ParsePrefixedIdentifier().ToString())); //FIXME
	    }
	}
	this.Skip(Token.RightBrace);
        ConstructArray consArr = new ConstructArray();
        consArr.SourceContext = this.scanner.CurrentSourceContext;
        consArr.Initializers = identifiers;
	//consArr.ElementType = TypeNode.GetTypeNode(??); //FIXME
	return consArr;	
    }
Example #9
0
 private Expression ParseNew(TokenSet followers){
   SourceContext ctx = this.scanner.CurrentSourceContext;
   Debug.Assert(this.currentToken == Token.New);
   this.GetNextToken();
   TypeNode allocator = null;
   if (this.currentToken == Token.LeftBracket) {
     this.GetNextToken();
     if (this.currentToken == Token.RightBracket) {
       return this.ParseNewImplicitlyTypedArray(ctx, followers);
     }
     // parse [Delayed] annotation (or allocator)
     allocator = this.ParseBaseTypeExpression(null, followers|Token.RightBracket, false, false);
     if (allocator == null){this.SkipTo(followers, Error.None); return null;}
     this.Skip(Token.RightBracket);
   }
   if (this.currentToken == Token.LeftBrace)
     return this.ParseNewAnonymousTypeInstance(ctx, followers);
   Expression owner = null;
   // Allow owner argument for each constructor: "new <ow> ..."
   if (this.currentToken == Token.LessThan) {
     this.GetNextToken();
     owner = this.ParsePrimaryExpression(followers | Token.GreaterThan);
     if (this.currentToken == Token.GreaterThan)
       this.GetNextToken();
   }
   // Make it explicit that the base type stops at "!", which is handled by
   // the code below.
   TypeNode t = this.ParseBaseTypeExpression(null, followers|Parser.InfixOperators|Token.LeftBracket|Token.LeftParenthesis|Token.RightParenthesis|Token.LogicalNot, false, false);
   if (t == null){this.SkipTo(followers, Error.None); return null;}
   if (this.currentToken == Token.Conditional) {
     TypeNode type = t;
     t = new NullableTypeExpression(type);
     t.SourceContext = type.SourceContext;
     t.SourceContext.EndPos = this.scanner.endPos;
     this.GetNextToken();
   }else if (this.currentToken == Token.LogicalNot){
     TypeNode type = t;
     t = new NonNullableTypeExpression(type);
     t.SourceContext = type.SourceContext;
     t.SourceContext.EndPos = this.scanner.endPos;
     this.GetNextToken();
   }else if (this.currentToken == Token.Multiply){
     this.GetNextToken();
     t = new PointerTypeExpression(t, t.SourceContext);
     t.SourceContext.EndPos = this.scanner.endPos;
     if (!this.inUnsafeCode)
       this.HandleError(t.SourceContext, Error.UnsafeNeeded);
   }
   ctx.EndPos = t.SourceContext.EndPos;
   // special hack [Delayed] in custom allocator position is used to mark the array as
   // a delayed construction. This annotation is used in the Definite Assignment analysis.
   //
   TypeExpression allocatorExp = allocator as TypeExpression;
   if (allocatorExp != null) {
     Identifier allocId = allocatorExp.Expression as Identifier;
     if (allocId != null && allocId.Name == "Delayed") {
       t = new RequiredModifierTypeExpression(t, TypeExpressionFor("Microsoft","Contracts","DelayedAttribute"));
       allocator = null; // not really a custom allocation
     }
   }
   int rank = this.ParseRankSpecifier(false, followers|Token.LeftBrace|Token.LeftBracket|Token.LeftParenthesis|Token.RightParenthesis);
   SourceContext lbCtx = ctx;
   while (rank > 0 && this.currentToken == Token.LeftBracket){
     lbCtx = this.scanner.CurrentSourceContext;
     t = new ArrayTypeExpression(t, rank);
     rank = this.ParseRankSpecifier(false, followers|Token.LeftBrace|Token.LeftBracket);
   }
   if (rank > 0){
     //new T[] {...} or new T[,] {{..} {...}...}, etc where T can also be an array type
     ConstructArray consArr = new ConstructArray();
     consArr.SourceContext = ctx;
     consArr.ElementType = consArr.ElementTypeExpression = t;
     consArr.Rank = rank;
     if (this.currentToken == Token.LeftBrace)
       consArr.Initializers = this.ParseArrayInitializer(rank, t, followers);
     else{
       if (Parser.UnaryStart[this.currentToken])
         this.HandleError(Error.ExpectedLeftBrace);
       else
         this.HandleError(Error.MissingArraySize);
       while (Parser.UnaryStart[this.currentToken]){
         this.ParseExpression(followers|Token.Comma|Token.RightBrace);
         if (this.currentToken != Token.Comma) break;
         this.GetNextToken();
       }
       if (this.currentToken == Token.RightBrace) this.GetNextToken();
       this.SkipTo(followers);
     }
     if (owner != null) {
       consArr.Owner = owner;
     }
     return consArr;
   }
   if (rank < 0){
     //new T[x] or new T[x,y] etc. possibly followed by an initializer or element type rank specifier
     ConstructArray consArr = new ConstructArray();
     consArr.SourceContext = ctx;
     consArr.Operands = this.ParseIndexList(followers|Token.LeftBrace|Token.LeftBracket, lbCtx, out consArr.SourceContext.EndPos);
     rank = consArr.Operands.Count;
     if (this.currentToken == Token.LeftBrace)
       consArr.Initializers = this.ParseArrayInitializer(rank, t, followers);
     else{
       int elementRank = this.ParseRankSpecifier(true, followers);
     tryAgain:
       if (elementRank > 0) t = this.ParseArrayType(elementRank, t, followers);
       if (this.currentToken == Token.LeftBrace)
         consArr.Initializers = this.ParseArrayInitializer(rank, t, followers);
       else{
         if (this.currentToken == Token.LeftBracket){ //new T[x][y] or something like that
           lbCtx = this.scanner.CurrentSourceContext;
           this.GetNextToken();
           SourceContext sctx = this.scanner.CurrentSourceContext;
           this.ParseIndexList(followers, lbCtx, out sctx.EndPos);
           this.HandleError(sctx, Error.InvalidArray);
           elementRank = 1;
           goto tryAgain;
         }else
           this.SkipTo(followers);
       }
     }
     consArr.ElementType = consArr.ElementTypeExpression = t;
     consArr.Rank = rank;
     if (owner != null) {
       consArr.Owner = owner;
     }
     return consArr;
   }
   ExpressionList arguments = null;
   SourceContext lpCtx = this.scanner.CurrentSourceContext;
   bool sawLeftParenthesis = false;
   if (this.currentToken == Token.LeftParenthesis){
     if (rank == 0 && t is NonNullableTypeExpression) {
       this.SkipTo(followers, Error.BadNewExpr);
       return null;
     }
     sawLeftParenthesis = true;
     this.GetNextToken();
     arguments = this.ParseArgumentList(followers, lpCtx, out ctx.EndPos);
   }else if (this.currentToken == Token.LeftBrace){
     Expression quant = this.ParseComprehension(followers);
     arguments = new ExpressionList(quant);
   }else{
     this.SkipTo(followers, Error.BadNewExpr);
     Construct c = new Construct();
     if (t is TypeExpression)
       c.Constructor = new MemberBinding(null, t, t.SourceContext);
     c.SourceContext = ctx;
     return c;
   }
   if (sawLeftParenthesis && this.currentToken == Token.LeftBrace){
   }
   Construct cons = new Construct(new MemberBinding(null, t), arguments);
   cons.SourceContext = ctx;
   if (owner != null)
     cons.Owner = owner;
   return cons;
 }
Example #10
0
    //HS D
    private BlockHole ParseBlockHole(TokenSet followers){	
	Debug.Assert(this.currentToken == Token.Hole);
	Hashtable templateParams = new Hashtable();
	this.GetNextToken();
	this.Skip(Token.LeftBrace);
	if (this.currentToken != Token.RightBrace){
	    string templateParam = this.scanner.GetTokenSource();
	    this.GetNextToken();
	    this.Skip(Token.Colon);
	    Expression templateParamVal = 
		this.currentToken == Token.IntegerLiteral ? this.ParseIntegerLiteral() : 
		(this.currentToken == Token.RealLiteral ? 
		 this.ParseRealLiteral() : this.ParseCommaSeparetedIdentifierSet());
	    templateParams[templateParam] = templateParamVal;
	    while (this.currentToken == Token.Comma){
		this.GetNextToken();
		templateParam = this.scanner.GetTokenSource();
		this.GetNextToken();
		this.Skip(Token.Colon);
		templateParamVal = 
		    this.currentToken == Token.IntegerLiteral ? this.ParseIntegerLiteral() : 
		    (this.currentToken == Token.RealLiteral ? 
		     this.ParseRealLiteral() : this.ParseCommaSeparetedIdentifierSet());
		templateParams[templateParam] = templateParamVal;
	    }
	}
	this.Skip(Token.RightBrace);
	Literal one = new Literal(1);
	ConstructArray empty = new ConstructArray();
	Literal repeat = templateParams.ContainsKey("repeat") ? (Literal) templateParams["repeat"] : one;
	Literal ifbranches = templateParams.ContainsKey("ifbranches") ? (Literal) templateParams["ifbranches"] : one;
	Literal branchops = templateParams.ContainsKey("branchops") ? (Literal) templateParams["branchops"] : one;
	Literal conjunctions = templateParams.ContainsKey("conjunctions") ? (Literal) templateParams["conjunctions"] : one;
	ConstructArray ops = templateParams.ContainsKey("ops") ? (ConstructArray) templateParams["ops"] : empty;
	ConstructArray condvars = templateParams.ContainsKey("condvars") ? (ConstructArray) templateParams["condvars"] : empty;
	ConstructArray argvars = templateParams.ContainsKey("argvars") ? (ConstructArray) templateParams["argvars"] : empty;
	SourceContext sctx = this.scanner.CurrentSourceContext;
	BlockHole result = new BlockHole(sctx, repeat, ifbranches, branchops, conjunctions, ops, condvars, argvars); //, this.currMethod, opMethods); 
	result.SourceContext = sctx;
	//HS D: HACK FIXME	
	DefineBlockHoleMethod(this.currentTypeNode);

	return result;
    }
Example #11
0
    /// <summary>
    /// </summary>
    /// <param name="consArr">Cloned</param>
    /// <returns></returns>
		public override Expression VisitConstructArray(ConstructArray consArr)
		{
			if(consArr.Initializers != null)
				throw new ApplicationException("ConstructArray Initializers field non-null!");

      consArr = (ConstructArray)consArr.Clone();
			consArr.Operands = this.VisitExpressionList(consArr.Operands);
			return consArr;
		}
            public override void VisitConstructArray(ConstructArray consArr)
            {
                this.seenConstructArray = true;

                base.VisitConstructArray(consArr);
            }
Example #13
0
        public override Expression VisitConstructArray(ConstructArray consArr)
        {
            if (consArr.Rank > 1)
                throw new NotImplementedException("Multi-dimensional arrays not yet supported");

            Write("new ");
            this.VisitTypeReference(consArr.ElementType);
            Write("[");
            if (consArr.Operands != null)
                this.VisitExpressionList(consArr.Operands);
            Write("]");
            if (consArr.Initializers != null)
            {
                Write(" { ");
                this.VisitExpressionList(consArr.Initializers);
                Write(" }");
            }
            return consArr;
        }
 public EventingVisitor(Action<ConstructArray> visitConstructArray) { VisitedConstructArray += visitConstructArray; } public event Action<ConstructArray> VisitedConstructArray; public override Expression VisitConstructArray(ConstructArray consArr) { if (VisitedConstructArray != null) VisitedConstructArray(consArr); return base.VisitConstructArray(consArr); }