Пример #1
0
 private QualifiedName RootQualifiedNameFor(Token tok, ISourceLocation sctx) 
   //^ requires tok == Token.Bool || tok == Token.Decimal || tok == Token.Sbyte ||
   //^   tok == Token.Byte || tok == Token.Short || tok == Token.Ushort ||
   //^   tok == Token.Int || tok == Token.Uint || tok == Token.Long ||
   //^   tok == Token.Ulong || tok == Token.Char || tok == Token.Float ||
   //^   tok == Token.Double || tok == Token.Object || tok == Token.String ||
   //^   tok == Token.Void;
 {
   RootNamespaceExpression rootNs = new RootNamespaceExpression(sctx);
   AliasQualifiedName systemNs = new AliasQualifiedName(rootNs, this.GetSimpleNameFor("System"), sctx);
   switch (tok) {
     case Token.Bool: return new QualifiedName(systemNs, this.GetSimpleNameFor("Boolean"), sctx);
     case Token.Decimal: return new QualifiedName(systemNs, this.GetSimpleNameFor("Decimal"), sctx);
     case Token.Sbyte: return new QualifiedName(systemNs, this.GetSimpleNameFor("SByte"), sctx);
     case Token.Byte: return new QualifiedName(systemNs, this.GetSimpleNameFor("Byte"), sctx);
     case Token.Short: return new QualifiedName(systemNs, this.GetSimpleNameFor("Int16"), sctx);
     case Token.Ushort: return new QualifiedName(systemNs, this.GetSimpleNameFor("UInt16"), sctx);
     case Token.Int: return new QualifiedName(systemNs, this.GetSimpleNameFor("Int32"), sctx);
     case Token.Uint: return new QualifiedName(systemNs, this.GetSimpleNameFor("UInt32"), sctx);
     case Token.Long: return new QualifiedName(systemNs, this.GetSimpleNameFor("Int64"), sctx);
     case Token.Ulong: return new QualifiedName(systemNs, this.GetSimpleNameFor("UInt64"), sctx);
     case Token.Char: return new QualifiedName(systemNs, this.GetSimpleNameFor("Char"), sctx);
     case Token.Float: return new QualifiedName(systemNs, this.GetSimpleNameFor("Single"), sctx);
     case Token.Double: return new QualifiedName(systemNs, this.GetSimpleNameFor("Double"), sctx);
     case Token.Object: return new QualifiedName(systemNs, this.GetSimpleNameFor("Object"), sctx);
     case Token.String: return new QualifiedName(systemNs, this.GetSimpleNameFor("String"), sctx);
     default:
       //^ assert tok == Token.Void;
       return new QualifiedName(systemNs, this.GetSimpleNameFor("Void"), sctx);
   }
 }
Пример #2
0
 private Expression ParseNamespaceOrTypeName(bool allowEmptyArguments, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
   //^ ensures result is SimpleName || result is AliasQualifiedName || result is QualifiedName || result is GenericTypeInstanceExpression;
 {
   SimpleName rootName = this.ParseSimpleName(followers|Token.Dot|Token.DoubleColon|Token.LessThan);
   Expression expression = rootName;
   if (rootName.Name.UniqueKey == this.nameTable.global.UniqueKey && this.currentToken == Token.DoubleColon)
     expression = new RootNamespaceExpression(rootName.SourceLocation);
   SourceLocationBuilder sctx = new SourceLocationBuilder(expression.SourceLocation);
   if (this.currentToken == Token.DoubleColon) {
     this.GetNextToken();
     SimpleName simpleName = this.ParseSimpleName(followers|Token.Dot|Token.LessThan);
     sctx.UpdateToSpan(simpleName.SourceLocation);
     expression = new AliasQualifiedName(expression, simpleName, sctx.GetSourceLocation());
   }
   //^ assume expression is SimpleName || expression is AliasQualifiedName; //RootNamespace will always disappear into AliasQualifiedName
 moreDots:
   while (this.currentToken == Token.Dot)
     //^ invariant expression is SimpleName || expression is AliasQualifiedName || expression is QualifiedName || expression is GenericTypeInstanceExpression;
   {
     this.GetNextToken();
     SimpleName simpleName = this.ParseSimpleName(followers|Token.Dot|Token.LessThan);
     sctx.UpdateToSpan(simpleName.SourceLocation);
     expression = new QualifiedName(expression, simpleName, sctx.GetSourceLocation());
   }
   if (this.currentToken == Token.LessThan) {
     //^ assume expression is SimpleName || expression is AliasQualifiedName || expression is QualifiedName; //Can only get back here if generic instance was followed by dot.
     TypeExpression genericType = new NamedTypeExpression(expression);
     while (this.currentToken == Token.LessThan)
       //^ invariant expression is SimpleName || expression is AliasQualifiedName || expression is QualifiedName || expression is GenericTypeInstanceExpression;
     {
       List<TypeExpression> arguments = this.ParseTypeArguments(sctx, allowEmptyArguments, followers|Token.Dot);
       expression = new GenericTypeInstanceExpression(genericType, arguments.AsReadOnly(), sctx.GetSourceLocation());
     }
     if (this.currentToken == Token.Dot) goto moreDots;
   }
   if (this.insideType && !this.insideBlock && !followers[this.currentToken])
     this.SkipTo(followers, Error.InvalidMemberDecl, this.scanner.GetTokenSource());
   else
     this.SkipTo(followers);
   return expression;
 }
Пример #3
0
 private Expression ParseQualifiedName(Expression qualifier, TokenSet followers)
   //^ requires this.currentToken == Token.Arrow || this.currentToken == Token.Dot || this.currentToken == Token.DoubleColon;
   //^ requires this.currentToken == Token.DoubleColon ==> qualifier is SimpleName || qualifier is RootNamespaceExpression;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   Token tok = this.currentToken;
   SourceLocationBuilder slb = new SourceLocationBuilder(qualifier.SourceLocation);
   this.GetNextToken();
   SimpleName name = this.ParseSimpleName(followers);
   slb.UpdateToSpan(name.SourceLocation);
   Expression result;
   if (tok == Token.Arrow) 
     result = new PointerQualifiedName(qualifier, name, slb);
   else if (tok == Token.DoubleColon) 
     result = new AliasQualifiedName(qualifier, name, slb);
   else {
     //^ assert tok == Token.Dot;
     result = new QualifiedName(qualifier, name, slb);
   }
   //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile;
   return result;
 }
Пример #4
0
 private NamespaceReferenceExpression ParseImportedNamespaceName(NameDeclaration name, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   Expression expression = new SimpleName(name, name.SourceLocation, false);
   SourceLocationBuilder sctx = new SourceLocationBuilder(expression.SourceLocation);
   if (this.currentToken == Token.DoubleColon) {
     this.GetNextToken();
     SimpleName simpleName = this.ParseSimpleName(followers|Token.Dot);
     sctx.UpdateToSpan(simpleName.SourceLocation);
     expression = new AliasQualifiedName(expression, simpleName, sctx.GetSourceLocation());
   }
   while (this.currentToken == Token.Dot)
     //^ invariant expression is SimpleName || expression is QualifiedName || expression is AliasQualifiedName;
   {
     this.GetNextToken();
     SimpleName simpleName = this.ParseSimpleName(followers|Token.Dot);
     sctx.UpdateToSpan(simpleName.SourceLocation);
     expression = new QualifiedName(expression, simpleName, sctx.GetSourceLocation());
   }
   NamespaceReferenceExpression result = new NamespaceReferenceExpression(expression, sctx.GetSourceLocation());
   this.SkipTo(followers);
   return result;
 }