示例#1
0
 private void ParseGenericTypeParameterConstraints(SpecSharpGenericTypeParameterDeclaration applicableParameter, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   TokenSet constraintStart = Parser.IdentifierOrNonReservedKeyword|Token.Struct|Token.Class|Token.New;
   if (!constraintStart[this.currentToken]) {
     this.HandleError(Error.TypeExpected);
     this.SkipTo(followers);
     return;
   }
   if (this.currentToken == Token.Class) {
     this.GetNextToken();
     applicableParameter.MustBeReferenceType = true;
   } else if (this.currentToken == Token.Struct) {
     this.GetNextToken();
     applicableParameter.MustBeValueType = true;
   }
   while (constraintStart[this.currentToken]) {
     if (this.currentToken == Token.Class || this.currentToken == Token.Struct) {
       this.HandleError(Error.RefValBoundMustBeFirst);
       this.GetNextToken(); continue;
     } else if (this.currentToken == Token.New) {
       this.GetNextToken();
       this.Skip(Token.LeftParenthesis);
       this.Skip(Token.RightParenthesis);
       applicableParameter.MustHaveDefaultConstructor = true;
       if (this.currentToken == Token.Comma) {
         this.HandleError(Error.NewBoundMustBeLast);
       }
       break;
     }
     //^ assume this.currentToken != Token.EndOfFile;
     applicableParameter.AddConstraint(this.ParseTypeExpression(false, false, constraintStart|Token.Comma|followers));
     if (this.currentToken != Token.Comma) break;
     this.GetNextToken();
   }
   this.SkipTo(followers);
 }
示例#2
0
 private void ParseGenericTypeParameterConstraintsClauses(List<Ast.GenericTypeParameterDeclaration> genericTypeParameters, TokenSet followers)
   // ^ requires forall{Ast.GenericTypeParameterDeclaration genericTypeParameter in genericTypeParameters; genericTypeParameter is SpecSharpGenericTypeParameterDeclaration};
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   while (this.currentToken == Token.Where) {
     this.GetNextToken();
     if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken])
       this.HandleError(Error.ExpectedIdentifier);
     NameDeclaration name = this.ParseNameDeclaration();
     SpecSharpGenericTypeParameterDeclaration/*?*/ applicableParameter = null;
     foreach (Ast.GenericTypeParameterDeclaration genericTypeParameter in genericTypeParameters)
       if (genericTypeParameter.Name.UniqueKey == name.UniqueKey) {
         //^ assume genericTypeParameter is SpecSharpGenericTypeParameterDeclaration; //follows from precondition
         applicableParameter = (SpecSharpGenericTypeParameterDeclaration)genericTypeParameter; 
         break; 
       }
     if (applicableParameter == null) {
       this.HandleError(name.SourceLocation, Error.TyVarNotFoundInConstraint);
       applicableParameter = new SpecSharpGenericTypeParameterDeclaration(null, name, (ushort)genericTypeParameters.Count);
     }
     this.Skip(Token.Colon);
     this.ParseGenericTypeParameterConstraints(applicableParameter, followers|Token.Where);
   }
   this.SkipTo(followers);
 }