private NameDeclaration GetNameDeclarationFor(string name, ISourceLocation sourceLocation) //^ ensures result.Value == name; { IName iname = this.nameTable.GetNameFor(name); NameDeclaration result = new NameDeclaration(iname, sourceLocation); //^ assume result.Value == name; return result; }
internal void AddStandardMembers(Compilation compilation, List<Statement> bodyOfMainRoutine) { NameDeclaration labelOfFirstStatement = new NameDeclaration(compilation.NameTable.GetNameFor("<<first statement>>"), SourceDummy.SourceLocation); FieldDeclaration labelField = new FieldDeclaration(null, 0, TypeMemberVisibility.Private, TypeExpression.For(compilation.PlatformType.SystemInt32.ResolvedType), labelOfFirstStatement, null, SourceDummy.SourceLocation); this.members.Add(labelField); this.AddMainMethod(compilation, bodyOfMainRoutine, labelField); this.AddEntryPointMethod(compilation); this.AddConstructor(compilation); }
private NamespaceImportDeclaration CreateNamespaceImport() { NameDeclaration dummyName = new NameDeclaration(Dummy.Name, SourceDummy.SourceLocation); SimpleName microsoft = new SimpleName(this.Compilation.NameTable.GetNameFor("Microsoft"), SourceDummy.SourceLocation, false); SimpleName smallBasic = new SimpleName(this.Compilation.NameTable.GetNameFor("SmallBasic"), SourceDummy.SourceLocation, false); SimpleName library = new SimpleName(this.Compilation.NameTable.GetNameFor("Library"), SourceDummy.SourceLocation, false); QualifiedName microsoftSmallBasic = new QualifiedName(microsoft, smallBasic, SourceDummy.SourceLocation); QualifiedName microsoftSmallBasicLibrary = new QualifiedName(microsoftSmallBasic, library, SourceDummy.SourceLocation); NamespaceReferenceExpression smallBasicLibrary = new NamespaceReferenceExpression(microsoftSmallBasicLibrary, SourceDummy.SourceLocation); return new NamespaceImportDeclaration(dummyName, smallBasicLibrary, SourceDummy.SourceLocation); }
private void ParseMethod(List<ITypeDeclarationMember> members, List<SourceCustomAttribute>/*?*/ attributes, List<ModifierToken> modifiers, TypeExpression type, List<TypeExpression>/*?*/ implementedInterfaces, NameDeclaration name, SourceLocationBuilder sctx, TokenSet followers) //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { MethodDeclaration.Flags flags = 0; TypeMemberVisibility visibility = this.ConvertToTypeMemberVisibility(modifiers); if (this.LookForModifier(modifiers, Token.Abstract, Error.None)) flags |= MethodDeclaration.Flags.Abstract; if (this.LookForModifier(modifiers, Token.New, Error.None)) flags |= MethodDeclaration.Flags.New; if (this.LookForModifier(modifiers, Token.Extern, Error.None)) flags |= MethodDeclaration.Flags.External; if (this.LookForModifier(modifiers, Token.Override, Error.None)) flags |= MethodDeclaration.Flags.Override; this.LookForModifier(modifiers, Token.Readonly, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Sealed, Error.None)) flags |= MethodDeclaration.Flags.Sealed; if (this.LookForModifier(modifiers, Token.Static, Error.None)) flags |= MethodDeclaration.Flags.Static; if (this.LookForModifier(modifiers, Token.Unsafe, Error.None)) flags |= MethodDeclaration.Flags.Unsafe; if (this.LookForModifier(modifiers, Token.Virtual, Error.None)) flags |= MethodDeclaration.Flags.Virtual; this.LookForModifier(modifiers, Token.Volatile, Error.InvalidModifier); List<Ast.GenericMethodParameterDeclaration> genericParameters = new List<Ast.GenericMethodParameterDeclaration>(); List<Ast.ParameterDeclaration> parameters = new List<Ast.ParameterDeclaration>(); List<Statement> statements = new List<Statement>(); SourceLocationBuilder bodyCtx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); BlockStatement body = new BlockStatement(statements, bodyCtx); bool isExtensionMethod; this.ParseGenericMethodParameters(genericParameters, followers|Token.LeftParenthesis|Token.Where|Token.LeftBrace|Token.Semicolon); this.ParseParameters(parameters, Token.RightParenthesis, followers|Token.Where|Token.LeftBrace|Token.Semicolon, out isExtensionMethod); if (isExtensionMethod) flags |= MethodDeclaration.Flags.ExtensionMethod; MethodDeclaration method = new MethodDeclaration(attributes, flags, visibility, type, implementedInterfaces, name, genericParameters, parameters, null, body, sctx); members.Add(method); // Now: how to get this.ParseGenericMethodParameterConstraintsClauses(genericParameters, followers|Token.LeftBrace|Token.Semicolon); //bool swallowedSemicolonAlready = false; //this.ParseMethodContract(oper, followers|Token.LeftBrace|Token.Semicolon, ref swallowedSemicolonAlready); this.ParseBody(statements, bodyCtx, followers); //^ assert followers[this.currentToken] || this.currentToken == Token.EndOfFile; sctx.UpdateToSpan(bodyCtx.GetSourceLocation()); //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile; }
private void ParseConstructor(List<ITypeDeclarationMember> members, List<SourceCustomAttribute>/*?*/ attributes, List<ModifierToken> modifiers, SourceLocationBuilder sctx, TokenSet followers) //^ requires Parser.IdentifierOrNonReservedKeyword[this.currentToken]; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { MethodDeclaration.Flags flags = MethodDeclaration.Flags.SpecialName; TypeMemberVisibility visibility = this.ConvertToTypeMemberVisibility(modifiers); this.LookForModifier(modifiers, Token.Abstract, Error.InvalidModifier); this.LookForModifier(modifiers, Token.New, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Extern, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Override, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Readonly, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Sealed, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Static, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Unsafe, Error.None)) flags |= MethodDeclaration.Flags.Unsafe; this.LookForModifier(modifiers, Token.Virtual, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Volatile, Error.InvalidModifier); NameDeclaration name = new NameDeclaration(this.nameTable.Ctor, this.scanner.SourceLocationOfLastScannedToken); //^ assume this.currentToken != Token.EndOfFile; //follows from the precondition this.GetNextToken(); List<Ast.ParameterDeclaration> parameters = new List<Ast.ParameterDeclaration>(); List<Statement> statements = new List<Statement>(); SourceLocationBuilder bodyCtx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); BlockStatement body = new BlockStatement(statements, bodyCtx); MethodDeclaration constructor = new MethodDeclaration(attributes, flags, visibility, new NamedTypeExpression(this.RootQualifiedNameFor(Token.Void)), null, name, null, parameters, null, body, sctx); members.Add(constructor); this.ParseParameters(parameters, Token.RightParenthesis, followers|Token.Where|Token.LeftBrace|Token.Semicolon|Token.Colon); SourceLocationBuilder callCtx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); Token kind = Token.Base; IEnumerable<Expression> arguments = Expression.EmptyCollection; if (this.currentToken == Token.Colon) { this.GetNextToken(); callCtx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); if (this.currentToken == Token.This) { kind = Token.This; this.GetNextToken(); if (this.currentToken == Token.LeftParenthesis) arguments = this.ParseArgumentList(callCtx, followers).AsReadOnly(); else { callCtx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); this.SkipTo(followers|Token.LeftBrace, Error.ExpectedLeftParenthesis); } } else if (this.currentToken == Token.Base) { this.GetNextToken(); if (this.currentToken == Token.LeftParenthesis) arguments = this.ParseArgumentList(callCtx, followers).AsReadOnly(); else { callCtx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); this.SkipTo(followers|Token.LeftBrace, Error.ExpectedLeftParenthesis); } } else { callCtx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); this.SkipTo(followers|Token.LeftBrace, Error.ThisOrBaseExpected); } } if (kind == Token.Base) { statements.Add(new FieldInitializerStatement()); statements.Add(new ExpressionStatement(new BaseClassConstructorCall(arguments, callCtx))); } else statements.Add(new ExpressionStatement(new ChainedConstructorCall(arguments, callCtx))); this.ParseBody(statements, bodyCtx, followers); //^ assert followers[this.currentToken] || this.currentToken == Token.EndOfFile; sctx.UpdateToSpan(bodyCtx.GetSourceLocation()); //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile; }
private void ParseField(List<ITypeDeclarationMember> members, List<SourceCustomAttribute>/*?*/ attributes, List<ModifierToken> modifiers, TypeExpression type, NameDeclaration name, SourceLocationBuilder sctx, TokenSet followers) //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { TypeMemberVisibility visibility = this.ConvertToTypeMemberVisibility(modifiers); FieldDeclaration.Flags flags = 0; this.LookForModifier(modifiers, Token.Abstract, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.New, Error.None)) flags |= FieldDeclaration.Flags.New; this.LookForModifier(modifiers, Token.Extern, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Override, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Readonly, Error.None)) flags |= FieldDeclaration.Flags.ReadOnly; this.LookForModifier(modifiers, Token.Sealed, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Static, Error.None)) flags |= FieldDeclaration.Flags.Static; if (this.LookForModifier(modifiers, Token.Unsafe, Error.None)) flags |= FieldDeclaration.Flags.Unsafe; this.LookForModifier(modifiers, Token.Virtual, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Volatile, Error.None)) flags |= FieldDeclaration.Flags.Volatile; TokenSet followersOrCommaOrSemicolon = followers|Token.Comma|Token.Semicolon; for (; ; ) { Expression/*?*/ initializer = null; if (this.currentToken == Token.Assign) { //bool savedParsingStatement = this.parsingStatement; //this.parsingStatement = true; this.GetNextToken(); if (this.currentToken == Token.LeftBrace) { //initializer = this.ParseArrayInitializer(type, followersOrCommaOrSemicolon); } else initializer = this.ParseExpression(followersOrCommaOrSemicolon); //if (this.currentToken != Token.EndOfFile) this.parsingStatement = savedParsingStatement; } sctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); FieldDeclaration f = new FieldDeclaration(attributes, flags, visibility, type, name, initializer, sctx); members.Add(f); if (this.currentToken != Token.Comma) break; this.GetNextToken(); name = this.ParseNameDeclaration(); sctx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); } this.SkipSemiColon(followers); }
/// <summary> /// Allocates a condition that must be true at the start of a method, possibly bundled with an exception that will be thrown if the condition does not hold. /// </summary> /// <param name="name">The name of the axiom. Used in error diagnostics. May be null.</param> /// <param name="condition">The condition that must be true at the start of the method that is associated with this Precondition instance.</param> /// <param name="isAxiom">An axiom is a type invariant whose truth is assumed rather than derived. Commonly used to make statements about the meaning of contract methods.</param> /// <param name="sourceLocation">The source location corresponding to the newly allocated source item.</param> public TypeInvariant(NameDeclaration/*?*/ name, Expression condition, bool isAxiom, ISourceLocation sourceLocation) : base(condition, sourceLocation) { this.name = name; this.isAxiom = isAxiom; }
internal VccFunctionTypeExpression(bool acceptsExtraArguments, CallingConvention callingConvention, TypeExpression returnType, NameDeclaration name, List<ParameterDeclaration> parameters, FunctionDeclarator declarator, ISourceLocation sourceLocation) : this(acceptsExtraArguments, callingConvention, returnType, name, parameters, sourceLocation) { this.declarator = declarator; }
private LambdaParameter ParseLambdaParameter(bool allowType, TokenSet followers) //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); bool isOut = false; bool isRef = false; Token firstToken = this.currentToken; NameDeclaration parameterName = new NameDeclaration(this.GetNameFor(this.scanner.GetIdentifierString()), this.scanner.SourceLocationOfLastScannedToken); TypeExpression/*?*/ parameterType = null; if (allowType) { if (this.currentToken == Token.Out) { isOut = true; this.GetNextToken(); } else if (this.currentToken == Token.Ref) { isRef = true; this.GetNextToken(); } parameterType = this.ParseTypeExpression(false, false, followers); if ((this.currentToken == Token.Comma || this.currentToken == Token.RightParenthesis) && Parser.IdentifierOrNonReservedKeyword[firstToken]) { parameterType = null; } else { parameterName = new NameDeclaration(this.GetNameFor(this.scanner.GetIdentifierString()), this.scanner.SourceLocationOfLastScannedToken); } } slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); LambdaParameter result = new LambdaParameter(isOut, isRef, parameterType, parameterName, slb); if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken]) this.HandleError(Error.ExpectedIdentifier); else { //^ assume this.currentToken != Token.EndOfFile; //follows from definition of Parser.IdentifierOrNonReservedKeyword this.GetNextToken(); } this.SkipTo(followers); return result; }
internal VccLocalFunctionDeclaration(NameDeclaration name, Expression/*?*/ initialValue, List<Specifier> specifiers, bool isSpec, ISourceLocation sourceLocation, FunctionDeclaration mangledFunctionDeclaration) : base(name, initialValue, specifiers, isSpec, sourceLocation) { this.mangledFunctionDeclaration = mangledFunctionDeclaration; }
private void GetOperatorName(ref NameDeclaration opName, ref bool canBeBinary, ref bool canBeUnary, ISourceLocation opCtxt) { switch (this.currentToken) { case Token.Plus: canBeBinary = true; canBeUnary = true; opName = this.GetNameDeclarationFor("op_Addition", opCtxt); break; case Token.Subtract: canBeBinary = true; canBeUnary = true; opName = this.GetNameDeclarationFor("op_Subtraction", opCtxt); break; case Token.Multiply: canBeBinary = true; opName = this.GetNameDeclarationFor("op_Multiply", opCtxt); break; case Token.Divide: canBeBinary = true; opName = this.GetNameDeclarationFor("op_Division", opCtxt); break; case Token.Remainder: canBeBinary = true; opName = this.GetNameDeclarationFor("op_Modulus", opCtxt); break; case Token.BitwiseAnd: canBeBinary = true; opName = this.GetNameDeclarationFor("op_BitwiseAnd", opCtxt); break; case Token.BitwiseOr: canBeBinary = true; opName = this.GetNameDeclarationFor("op_BitwiseOr", opCtxt); break; case Token.BitwiseXor: canBeBinary = true; opName = this.GetNameDeclarationFor("op_ExclusiveOr", opCtxt); break; case Token.LeftShift: canBeBinary = true; opName = this.GetNameDeclarationFor("op_LeftShift", opCtxt); break; case Token.RightShift: canBeBinary = true; opName = this.GetNameDeclarationFor("op_RightShift", opCtxt); break; case Token.Equal: canBeBinary = true; opName = this.GetNameDeclarationFor("op_Equality", opCtxt); break; case Token.NotEqual: canBeBinary = true; opName = this.GetNameDeclarationFor("op_Inequality", opCtxt); break; case Token.GreaterThan: canBeBinary = true; opName = this.GetNameDeclarationFor("op_GreaterThan", opCtxt); break; case Token.LessThan: canBeBinary = true; opName = this.GetNameDeclarationFor("op_LessThan", opCtxt); break; case Token.GreaterThanOrEqual: canBeBinary = true; opName = this.GetNameDeclarationFor("op_GreaterThanOrEqual", opCtxt); break; case Token.LessThanOrEqual: canBeBinary = true; opName = this.GetNameDeclarationFor("op_LessThanOrEqual", opCtxt); break; case Token.LogicalNot: canBeUnary = true; opName = this.GetNameDeclarationFor("op_LogicalNot", opCtxt); break; case Token.BitwiseNot: canBeUnary = true; opName = this.GetNameDeclarationFor("op_OnesComplement", opCtxt); break; case Token.AddOne: canBeUnary = true; opName = this.GetNameDeclarationFor("op_Increment", opCtxt); break; case Token.SubtractOne: canBeUnary = true; opName = this.GetNameDeclarationFor("op_Decrement", opCtxt); break; case Token.True: canBeUnary = true; opName = this.GetNameDeclarationFor("op_True", opCtxt); break; case Token.False: canBeUnary = true; opName = this.GetNameDeclarationFor("op_False", opCtxt); break; case Token.Implicit: canBeUnary = true; opName = this.GetNameDeclarationFor("op_Implicit", opCtxt); this.HandleError(opName.SourceLocation, Error.BadOperatorSyntax, "implicit"); break; case Token.Explicit: canBeUnary = true; opName = this.GetNameDeclarationFor("op_Explicit", opCtxt); this.HandleError(opName.SourceLocation, Error.BadOperatorSyntax, "explicit"); break; } }
private void ParseProperty(List<ITypeDeclarationMember> members, List<SourceCustomAttribute>/*?*/ attributes, List<ModifierToken> modifiers, TypeExpression type, List<TypeExpression>/*?*/ implementedInterfaces, NameDeclaration name, SourceLocationBuilder sctx, TokenSet followers) //^ requires (this.currentToken == Token.This && name.Value == "Item") || this.currentToken == Token.LeftBrace; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { PropertyDeclaration.Flags flags = 0; TypeMemberVisibility visibility = this.ConvertToTypeMemberVisibility(modifiers); if (this.LookForModifier(modifiers, Token.Abstract, Error.None)) flags |= PropertyDeclaration.Flags.Abstract; if (this.LookForModifier(modifiers, Token.New, Error.None)) flags |= PropertyDeclaration.Flags.New; if (this.LookForModifier(modifiers, Token.Extern, Error.None)) flags |= PropertyDeclaration.Flags.External; if (this.LookForModifier(modifiers, Token.Override, Error.None)) flags |= PropertyDeclaration.Flags.Override; this.LookForModifier(modifiers, Token.Readonly, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Sealed, Error.None)) flags |= PropertyDeclaration.Flags.Sealed; if (this.LookForModifier(modifiers, Token.Static, Error.None)) flags |= PropertyDeclaration.Flags.Static; if (this.LookForModifier(modifiers, Token.Unsafe, Error.None)) flags |= PropertyDeclaration.Flags.Unsafe; if (this.LookForModifier(modifiers, Token.Virtual, Error.None)) flags |= PropertyDeclaration.Flags.Virtual; this.LookForModifier(modifiers, Token.Volatile, Error.InvalidModifier); bool isIndexer = this.currentToken == Token.This; this.GetNextToken(); List<Ast.ParameterDeclaration>/*?*/ parameters = null; if (isIndexer) { parameters = new List<Ast.ParameterDeclaration>(); this.ParseParameters(parameters, Token.RightBracket, followers|Token.LeftBrace); this.Skip(Token.LeftBrace); } //if (this.currentToken == Token.LeftBrace) // this.GetNextToken(); //else { // Error e = Error.ExpectedLeftBrace; // if (implementedInterfaces != null) e = Error.ExplicitEventFieldImpl; // this.SkipTo(followers|Token.LeftBracket|Token.Add|Token.Remove|Token.RightBrace, e); //} TokenSet followersOrRightBrace = followers|Token.RightBrace; List<SourceCustomAttribute>/*?*/ getterAttributes = null; TypeMemberVisibility getterVisibility = visibility; BlockStatement/*?*/ getterBody = null; List<SourceCustomAttribute>/*?*/ setterAttributes = null; BlockStatement/*?*/ setterBody = null; TypeMemberVisibility setterVisibility = visibility; bool alreadyComplainedAboutModifier = false; List<ModifierToken>/*?*/ accessorModifiers = null; SourceLocationBuilder/*?*/ bodyCtx = null; for (; ; ) { if (bodyCtx == null) bodyCtx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); List<SourceCustomAttribute>/*?*/ accessorAttrs = this.ParseAttributes(followers | Parser.GetOrLeftBracketOrSetOrModifier | Token.LeftBrace); switch (this.currentToken) { case Token.Get: if (accessorModifiers != null) { getterVisibility = this.ConvertToTypeMemberVisibility(accessorModifiers); accessorModifiers = null; } getterAttributes = accessorAttrs; if (getterBody != null) this.HandleError(Error.DuplicateAccessor); this.GetNextToken(); bool bodyAllowed = true; if (this.currentToken == Token.Semicolon) { this.GetNextToken(); bodyAllowed = false; } //this.ParseMethodContract(m, followers|Token.LeftBrace|Token.Semicolon, ref swallowedSemicolonAlready); if (bodyAllowed) getterBody = this.ParseBody(bodyCtx, followersOrRightBrace|Token.Set); bodyCtx = null; continue; case Token.Set: if (accessorModifiers != null) { setterVisibility = this.ConvertToTypeMemberVisibility(accessorModifiers); accessorModifiers = null; } setterAttributes = accessorAttrs; if (setterBody != null) this.HandleError(Error.DuplicateAccessor); this.GetNextToken(); bodyAllowed = true; if (this.currentToken == Token.Semicolon) { this.GetNextToken(); bodyAllowed = false; } //this.ParseMethodContract(m, followers|Token.LeftBrace|Token.Semicolon, ref swallowedSemicolonAlready); if (bodyAllowed) setterBody = this.ParseBody(bodyCtx, followersOrRightBrace|Token.Get); bodyCtx = null; continue; case Token.Protected: case Token.Internal: case Token.Private: if (accessorModifiers != null) goto case Token.Public; accessorModifiers = this.ParseModifiers(); continue; case Token.Public: case Token.New: case Token.Abstract: case Token.Sealed: case Token.Static: case Token.Readonly: case Token.Volatile: case Token.Virtual: case Token.Override: case Token.Extern: case Token.Unsafe: if (!alreadyComplainedAboutModifier) this.HandleError(Error.NoModifiersOnAccessor); this.GetNextToken(); alreadyComplainedAboutModifier = true; continue; case Token.RightBrace: break; default: this.HandleError(Error.GetOrSetExpected); break; } break; } sctx.UpdateToSpan(bodyCtx.GetSourceLocation()); PropertyDeclaration prop = new PropertyDeclaration(attributes, flags, visibility, type, implementedInterfaces, name, parameters, getterAttributes, getterBody, getterVisibility, setterAttributes, setterBody, setterVisibility, sctx.GetSourceLocation()); members.Add(prop); this.SkipOverTo(Token.RightBrace, followers); }
private VccFunctionTypeExpression(BlockStatement containingBlock, VccFunctionTypeExpression template) : base(containingBlock, template) { this.AcceptsExtraArguments = template.AcceptsExtraArguments; this.CallingConvention = template.CallingConvention; this.ReturnType = (TypeExpression)template.ReturnType.MakeCopyFor(containingBlock); this.Name = template.Name.MakeCopyFor(containingBlock.Compilation); this.parameters = new List<ParameterDeclaration>(template.parameters); this.declarator = template.declarator; }
private void ParseUsingDirective(List<INamespaceDeclarationMember> members, TokenSet followers) //^ requires this.currentToken == Token.Using; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { SourceLocationBuilder sctx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); this.GetNextToken(); if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken]) { this.SkipTo(followers, Error.ExpectedIdentifier); return; } NameDeclaration name = this.ParseNameDeclaration(); TokenSet followersOrSemicolon = followers|Token.Semicolon; if (this.currentToken == Token.Assign) { this.GetNextToken(); Expression referencedNamespaceOrType = this.ParseNamespaceOrTypeName(false, followersOrSemicolon); sctx.UpdateToSpan(referencedNamespaceOrType.SourceLocation); members.Add(new AliasDeclaration(name, referencedNamespaceOrType, sctx.GetSourceLocation())); } else { NamespaceReferenceExpression namespaceName = this.ParseImportedNamespaceName(name, followersOrSemicolon); sctx.UpdateToSpan(namespaceName.SourceLocation); NameDeclaration dummyName = new NameDeclaration(Dummy.Name, this.scanner.SourceLocationOfLastScannedToken); members.Add(new NamespaceImportDeclaration(dummyName, namespaceName, sctx.GetSourceLocation())); } this.SkipSemiColon(followers); }
internal RootClassDeclaration(NameDeclaration name, List<ITypeDeclarationMember> members, ISourceLocation sourceLocation) : base(null, Flags.Static, name, new List<GenericTypeParameterDeclaration>(0), new List<TypeExpression>(0), members, sourceLocation) { this.members = members; }
private LabeledStatement ParseLabel(SimpleName rootName, TokenSet followers) //^ requires this.currentToken == Token.Colon; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { NameDeclaration labelName = new NameDeclaration(rootName.Name, rootName.SourceLocation); //^ assume this.rootClass != null; this.rootClass.AddLabel(rootName); SourceLocationBuilder slb = new SourceLocationBuilder(rootName.SourceLocation); slb.UpdateToSpan(this.scanner.CurrentSourceLocation); this.GetNextToken(); LabeledStatement result = new LabeledStatement(labelName, new EmptyStatement(false, SourceDummy.SourceLocation), slb); this.SkipOverTo(Token.EndOfLine, followers); return result; }
protected VccLabeledExpression(BlockStatement containingBlock, VccLabeledExpression template) : base(containingBlock, template) { this.expression = template.expression.MakeCopyFor(containingBlock); this.label = template.label.MakeCopyFor(containingBlock.Compilation); }
public VccLabeledExpression(Expression expression, NameDeclaration label, ISourceLocation sourceLocation) : base(sourceLocation) { this.expression = expression; this.label = label; }
protected virtual LocalDefinition CreateLocalTempForProjection(List<Statement> statements) { IName dummyName = this.ContainingBlock.Helper.NameTable.GetNameFor("__temp" + this.SourceLocation.StartIndex); NameDeclaration tempName = new NameDeclaration(dummyName, this.SourceLocation); LocalDeclaration temp = new LocalDeclaration(false, false, tempName, null, this.SourceLocation); List<LocalDeclaration> declarations = new List<LocalDeclaration>(1) {temp}; LocalDeclarationsStatement statement = new LocalDeclarationsStatement(false, false, false, TypeExpression.For(this.structureTypeExpression.ResolvedType), declarations, this.SourceLocation); statements.Add(statement); statement.SetContainingBlock(this.ContainingBlock); temp.SetContainingLocalDeclarationsStatement(statement); return temp.LocalVariable; }
private void ParseOperator(List<ITypeDeclarationMember> members, List<SourceCustomAttribute>/*?*/ attributes, List<ModifierToken> modifiers, TypeExpression/*?*/ resultType, SourceLocationBuilder sctx, TokenSet followers) //^ requires this.currentToken == Token.Explicit || this.currentToken == Token.Implicit || this.currentToken == Token.Operator; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { MethodDeclaration.Flags flags = MethodDeclaration.Flags.SpecialName; TypeMemberVisibility visibility = this.ConvertToTypeMemberVisibility(modifiers); this.LookForModifier(modifiers, Token.Abstract, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Extern, Error.None)) flags |= MethodDeclaration.Flags.External; this.LookForModifier(modifiers, Token.New, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Override, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Readonly, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Sealed, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Static, Error.None)) flags |= MethodDeclaration.Flags.Static; if (this.LookForModifier(modifiers, Token.Unsafe, Error.None)) flags |= MethodDeclaration.Flags.Unsafe; this.LookForModifier(modifiers, Token.Virtual, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Volatile, Error.InvalidModifier); NameDeclaration opName = new NameDeclaration(this.nameTable.EmptyName, this.scanner.SourceLocationOfLastScannedToken); SourceLocationBuilder ctx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); ISourceLocation symCtx = this.scanner.SourceLocationOfLastScannedToken; bool canBeBinary = false; bool canBeUnary = false; switch (this.currentToken) { case Token.Explicit: this.GetNextToken(); ctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); opName = this.GetNameDeclarationFor("op_Explicit", ctx.GetSourceLocation()); this.Skip(Token.Operator); if (resultType != null && this.currentToken == Token.LeftParenthesis) this.HandleError(opName.SourceLocation, Error.BadOperatorSyntax, "explicit"); else resultType = this.ParseTypeExpression(false, false, followers|Token.LeftParenthesis); canBeUnary = true; break; case Token.Implicit: this.GetNextToken(); ctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); opName = this.GetNameDeclarationFor("op_Implicit", ctx.GetSourceLocation()); this.Skip(Token.Operator); if (resultType != null && this.currentToken == Token.LeftParenthesis) this.HandleError(opName.SourceLocation, Error.BadOperatorSyntax, "implicit"); else resultType = this.ParseTypeExpression(false, false, followers|Token.LeftParenthesis); canBeUnary = true; break; case Token.Operator: this.GetNextToken(); symCtx = this.scanner.SourceLocationOfLastScannedToken; ctx.UpdateToSpan(symCtx); this.GetOperatorName(ref opName, ref canBeBinary, ref canBeUnary, ctx.GetSourceLocation()); if (this.currentToken != Token.EndOfFile) this.GetNextToken(); if (resultType == null) { this.HandleError(Error.BadOperatorSyntax2, ctx.GetSourceLocation().Source); if (this.currentToken != Token.LeftParenthesis) resultType = this.ParseTypeExpression(false, false, followers|Token.LeftParenthesis); else resultType = new NamedTypeExpression(this.RootQualifiedNameFor(Token.Void)); } break; default: //^ assert false; break; } //Parse the parameter list List<Ast.ParameterDeclaration> parameters = new List<Ast.ParameterDeclaration>(); this.ParseParameters(parameters, Token.RightParenthesis, followers|Token.LeftBrace|Token.Semicolon|Token.Requires|Token.Modifies|Token.Ensures|Token.Where|Token.Throws); switch (parameters.Count) { case 1: if (!canBeUnary) this.HandleError(symCtx, Error.OvlUnaryOperatorExpected); if (canBeBinary && opName != null) { if (opName.Value == "op_Addition") opName = this.GetNameDeclarationFor("op_UnaryPlus", opName.SourceLocation); else if (opName.Value == "op_Subtraction") opName = this.GetNameDeclarationFor("op_UnaryNegation", opName.SourceLocation); } break; case 2: if (!canBeBinary) if (canBeUnary) this.HandleError(symCtx, Error.WrongParsForUnaryOp, opName.SourceLocation.Source); else this.HandleError(symCtx, Error.OvlBinaryOperatorExpected); break; default: if (canBeBinary) this.HandleError(symCtx, Error.WrongParsForBinOp, opName.SourceLocation.Source); else if (canBeUnary) this.HandleError(symCtx, Error.WrongParsForUnaryOp, opName.SourceLocation.Source); else this.HandleError(symCtx, Error.OvlBinaryOperatorExpected); break; } ctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); //bool swallowedSemicolonAlready = false; //this.ParseMethodContract(oper, followers|Token.LeftBrace|Token.Semicolon, ref swallowedSemicolonAlready); BlockStatement body = this.ParseBody(followers); //^ assert followers[this.currentToken] || this.currentToken == Token.EndOfFile; sctx.UpdateToSpan(body.SourceLocation); MethodDeclaration method = new MethodDeclaration(attributes, flags, visibility, resultType, null, opName, null, parameters, null, body, sctx.GetSourceLocation()); members.Add(method); //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile; }
/// <summary> /// Allocates a copy of the given name declaration, but using the name table of the given /// target compilation to obtain the corresponding IName value. /// </summary> /// <param name="targetCompilation">The compilation that is the root node of the AST of which the new name declaration will be a part.</param> /// <param name="template">A name declaration from another declaration, whose source location and value is to be copied by the new name declaration.</param> protected NameDeclaration(Compilation targetCompilation, NameDeclaration template) { this.sourceLocation = template.SourceLocation; this.name = targetCompilation.NameTable.GetNameFor(template.Value); }
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; }
private void ParseEventWithAccessors(List<ITypeDeclarationMember> members, List<SourceCustomAttribute>/*?*/ attributes, List<ModifierToken> modifiers, TypeExpression type, NameDeclaration name, SourceLocationBuilder sctx, TokenSet followers) //^ requires this.currentToken == Token.Dot || this.currentToken == Token.LessThan || this.currentToken == Token.LeftBrace; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { EventDeclaration.Flags flags = 0; TypeMemberVisibility visibility = this.ConvertToTypeMemberVisibility(modifiers); if (this.LookForModifier(modifiers, Token.Abstract, Error.None)) flags |= EventDeclaration.Flags.Abstract; if (this.LookForModifier(modifiers, Token.New, Error.None)) flags |= EventDeclaration.Flags.New; if (this.LookForModifier(modifiers, Token.Extern, Error.None)) flags |= EventDeclaration.Flags.External; if (this.LookForModifier(modifiers, Token.Override, Error.None)) flags |= EventDeclaration.Flags.Override; this.LookForModifier(modifiers, Token.Readonly, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Sealed, Error.None)) flags |= EventDeclaration.Flags.Sealed; if (this.LookForModifier(modifiers, Token.Static, Error.None)) flags |= EventDeclaration.Flags.Static; if (this.LookForModifier(modifiers, Token.Unsafe, Error.None)) flags |= EventDeclaration.Flags.Unsafe; if (this.LookForModifier(modifiers, Token.Virtual, Error.None)) flags |= EventDeclaration.Flags.Virtual; this.LookForModifier(modifiers, Token.Volatile, Error.InvalidModifier); List<TypeExpression>/*?*/ implementedInterfaces = null; Expression implementedInterface = this.ParseImplementedInterfacePlusName(ref name, false, followers); QualifiedName/*?*/ qual = implementedInterface as QualifiedName; if (qual != null) { implementedInterfaces = new List<TypeExpression>(1); GenericTypeInstanceExpression/*?*/ gte = qual.Qualifier as GenericTypeInstanceExpression; if (gte != null) implementedInterfaces.Add(gte); else { //^ assume qual.Qualifier is SimpleName || qual.Qualifier is QualifiedName; //follows from post condition of ParseImplementedInterfacePlusName implementedInterfaces.Add(new NamedTypeExpression(qual.Qualifier)); } } if (this.currentToken == Token.LeftBrace) this.GetNextToken(); else{ Error e = Error.ExpectedLeftBrace; if (implementedInterfaces != null) e = Error.ExplicitEventFieldImpl; this.SkipTo(followers|Token.LeftBracket|Token.Add|Token.Remove|Token.RightBrace, e); } TokenSet followersOrRightBrace = followers|Token.RightBrace; List<SourceCustomAttribute>/*?*/ adderAttributes = null; BlockStatement/*?*/ adderBody = null; List<SourceCustomAttribute>/*?*/ removerAttributes = null; BlockStatement/*?*/ removerBody = null; bool alreadyComplainedAboutModifier = false; for (; ; ) { List<SourceCustomAttribute>/*?*/ accessorAttrs = this.ParseAttributes(followers|Parser.AddOrRemoveOrModifier|Token.LeftBrace); switch (this.currentToken) { case Token.Add: adderAttributes = accessorAttrs; if (adderBody != null) this.HandleError(Error.DuplicateAccessor); this.GetNextToken(); if (this.currentToken != Token.LeftBrace) { this.SkipTo(followersOrRightBrace|Token.Remove, Error.AddRemoveMustHaveBody); } else adderBody = this.ParseBody(followersOrRightBrace|Token.Remove); continue; case Token.Remove: removerAttributes = accessorAttrs; if (removerBody != null) this.HandleError(Error.DuplicateAccessor); this.GetNextToken(); if (this.currentToken != Token.LeftBrace) { this.SkipTo(followersOrRightBrace|Token.Remove, Error.AddRemoveMustHaveBody); removerBody = null; } else removerBody = this.ParseBody(followersOrRightBrace|Token.Add); continue; case Token.New: case Token.Public: case Token.Protected: case Token.Internal: case Token.Private: case Token.Abstract: case Token.Sealed: case Token.Static: case Token.Readonly: case Token.Volatile: case Token.Virtual: case Token.Override: case Token.Extern: case Token.Unsafe: if (!alreadyComplainedAboutModifier) this.HandleError(Error.NoModifiersOnAccessor); this.GetNextToken(); alreadyComplainedAboutModifier = true; continue; default: this.HandleError(Error.AddOrRemoveExpected); break; } break; } if (adderBody == null) adderBody = null; if (removerBody == null) removerBody = null; EventDeclaration evnt = new EventDeclaration(attributes, flags, visibility, type, implementedInterfaces, name, adderAttributes, adderBody, removerAttributes, removerBody, sctx.GetSourceLocation()); members.Add(evnt); this.SkipOverTo(Token.RightBrace, followers); }
private Expression ParseImplementedInterfacePlusName(ref NameDeclaration name, bool allowThis, TokenSet followers) //^ ensures result is SimpleName || result is QualifiedName; //^ ensures result is QualifiedName ==> (((QualifiedName)result).Qualifier is SimpleName || //^ ((QualifiedName)result).Qualifier is QualifiedName || ((QualifiedName)result).Qualifier is GenericTypeInstanceExpression); { Expression implementedInterface = new SimpleName(name, name.SourceLocation, false); while (this.currentToken == Token.Dot || this.currentToken == Token.LessThan) //^ invariant implementedInterface is SimpleName || implementedInterface is QualifiedName; //The following invariant does not hold, it seems. Fix it. //^ invariant implementedInterface is QualifiedName ==> (((QualifiedName)implementedInterface).Qualifier is SimpleName || //^ ((QualifiedName)implementedInterface).Qualifier is QualifiedName || ((QualifiedName)implementedInterface).Qualifier is GenericTypeInstanceExpression); { if (this.currentToken == Token.LessThan) { //^ assume implementedInterface is SimpleName || implementedInterface is QualifiedName; TypeExpression genericType = new NamedTypeExpression(implementedInterface); SourceLocationBuilder ctx = new SourceLocationBuilder(implementedInterface.SourceLocation); List<TypeExpression> typeArguments = this.ParseTypeArguments(ctx, false, followers|Token.Dot|Token.LeftBrace); implementedInterface = new GenericTypeInstanceExpression(genericType, typeArguments, ctx); } this.Skip(Token.Dot); if (this.currentToken == Token.This && allowThis) { name = this.GetNameDeclarationFor("Item", this.scanner.SourceLocationOfLastScannedToken); } else { if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken]) this.SkipTo(followers|Parser.IdentifierOrNonReservedKeyword|Token.LeftBrace, Error.ExpectedIdentifier); name = this.ParseNameDeclaration(); } SourceLocationBuilder ctx1 = new SourceLocationBuilder(implementedInterface.SourceLocation); ctx1.UpdateToSpan(name.SourceLocation); implementedInterface = new QualifiedName(implementedInterface, new SimpleName(name, name.SourceLocation, false), ctx1); } return implementedInterface; }
private Expression ParseLambda(SimpleName parameterName, TokenSet followers) //^ requires this.currentToken == Token.Lambda; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { NameDeclaration paramName = new NameDeclaration(parameterName.Name, parameterName.SourceLocation); SourceLocationBuilder slb = new SourceLocationBuilder(parameterName.SourceLocation); LambdaParameter parameter = new LambdaParameter(false, false, null, paramName, parameterName.SourceLocation); List<LambdaParameter> parameters = new List<LambdaParameter>(1); parameters.Add(parameter); //^ assume this.currentToken == Token.Lambda; //follows from the precondition return this.ParseLambda(parameters, slb, followers); }
private void ParseDestructor(IName parentTypeName, List<ITypeDeclarationMember> members, List<SourceCustomAttribute>/*?*/ attributes, List<ModifierToken> modifiers, SourceLocationBuilder sctx, TokenSet followers) //^ requires this.currentToken == Token.BitwiseNot; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { this.GetNextToken(); MethodDeclaration.Flags flags = MethodDeclaration.Flags.SpecialName; this.LookForModifier(modifiers, Token.Abstract, Error.InvalidModifier); this.LookForModifier(modifiers, Token.New, Error.InvalidModifier); if (this.LookForModifier(modifiers, Token.Extern, Error.None)) flags |= MethodDeclaration.Flags.External; this.LookForModifier(modifiers, Token.Override, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Readonly, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Sealed, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Static, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Unsafe, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Virtual, Error.InvalidModifier); this.LookForModifier(modifiers, Token.Volatile, Error.InvalidModifier); if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken]) this.HandleError(Error.ExpectedIdentifier); NameDeclaration name = this.ParseNameDeclaration(); if (name.UniqueKey != parentTypeName.UniqueKey) this.HandleError(Error.WrongNameForDestructor); name = new NameDeclaration(this.GetNameFor("Finalize"), name.SourceLocation); List<Ast.ParameterDeclaration> parameters = new List<Ast.ParameterDeclaration>(0); this.ParseParameters(parameters, Token.RightParenthesis, followers|Token.LeftBrace); if (parameters.Count > 0) { this.HandleError(parameters[0].SourceLocation, Error.ExpectedRightParenthesis); parameters.Clear(); } BlockStatement body = this.ParseBody(followers); //^ assert followers[this.currentToken] || this.currentToken == Token.EndOfFile; sctx.UpdateToSpan(body.SourceLocation); MethodDeclaration method = new MethodDeclaration(attributes, flags, TypeMemberVisibility.Private, this.GetTypeExpressionFor(Token.Void, name.SourceLocation), null, name, null, parameters, null, body, sctx.GetSourceLocation()); members.Add(method); //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile; }
/// <summary> /// Allocates local declaration that appears as part of a statement containing a collection of local declarations, all with the same type. /// </summary> /// <param name="name">The name of the local.</param> /// <param name="initialValue">The value, if any, to assign to the local as its initial value. May be null.</param> /// <param name="isSpec">A flag that indicates if this declaration is spec code</param> /// <param name="sourceLocation">The source location corresponding to the newly allocated expression.</param> /// <param name="specifiers">The specifiers of this declaration</param> public VccLocalDeclaration(NameDeclaration name, Expression/*?*/ initialValue, List<Specifier> specifiers, bool isSpec, ISourceLocation sourceLocation) : base(false, false, name, initialValue, sourceLocation) { this.specifiers = specifiers; this.isSpec = isSpec; }
private void ParseConstructorOrFieldOrMethodOrPropertyOrStaticInitializer(IName typeName, List<ITypeDeclarationMember> members, List<SourceCustomAttribute>/*?*/ attributes, List<ModifierToken> modifiers, SourceLocationBuilder sctx, TokenSet followers) //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { if (Parser.IdentifierOrNonReservedKeyword[this.currentToken] && this.scanner.GetIdentifierString() == typeName.Value && this.PeekNextToken() == Token.LeftParenthesis) { //^ assume Parser.IdentifierOrNonReservedKeyword[this.currentToken]; //TODO: Boogie bug. The above condition ought to do it. this.ParseConstructor(members, attributes, modifiers, sctx, followers|Token.Semicolon); if (this.currentToken == Token.Semicolon) this.GetNextToken(); this.SkipTo(followers); return; } SourceLocationBuilder idCtx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); TypeExpression type = this.ParseTypeExpression(false, false, followers|Parser.IdentifierOrNonReservedKeyword|Token.Explicit|Token.Implicit); bool badModifier = false; tryAgain: switch (this.currentToken) { case Token.This: NameDeclaration itemId = this.GetNameDeclarationFor("Item", this.scanner.SourceLocationOfLastScannedToken); this.ParseProperty(members, attributes, modifiers, type, null, itemId, sctx, followers); return; case Token.Explicit: case Token.Implicit: case Token.Operator: this.ParseOperator(members, attributes, modifiers, type, sctx, followers); return; case Token.New: case Token.Public: case Token.Protected: case Token.Internal: case Token.Private: case Token.Abstract: case Token.Sealed: case Token.Static: case Token.Readonly: case Token.Volatile: case Token.Virtual: case Token.Override: case Token.Extern: case Token.Unsafe: if (this.scanner.TokenIsFirstAfterLineBreak) break; if (!badModifier) { this.HandleError(Error.BadModifierLocation, this.scanner.GetTokenSource()); badModifier = true; } this.GetNextToken(); goto tryAgain; case Token.LeftParenthesis: case Token.LessThan: if (type is NamedTypeExpression && ((NamedTypeExpression)type).Expression is SimpleName) { this.HandleError(type.SourceLocation, Error.MemberNeedsType); NameDeclaration methName = new NameDeclaration(((SimpleName)((NamedTypeExpression)type).Expression).Name, type.SourceLocation); this.ParseMethod(members, attributes, modifiers, this.GetTypeExpressionFor(Token.Void, methName.SourceLocation), null, methName, sctx, followers); return; } break; default: if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken]) { if (followers[this.currentToken]) this.HandleError(Error.ExpectedIdentifier); else this.SkipTo(followers); this.ParseField(members, attributes, modifiers, type, this.GetNameDeclarationFor("", this.scanner.SourceLocationOfLastScannedToken), sctx, followers); return; } break; } NameDeclaration name = this.ParseNameDeclaration(); List<TypeExpression>/*?*/ implementedInterfaces = null; if (this.currentToken != Token.LessThan || !this.AtMethodTypeParameterList()) { Expression implementedInterface = this.ParseImplementedInterfacePlusName(ref name, true, followers|Token.LeftBrace|Token.LeftBracket|Token.LeftParenthesis|Token.LessThan); QualifiedName/*?*/ qual = implementedInterface as QualifiedName; if (qual != null) { implementedInterfaces = new List<TypeExpression>(1); GenericTypeInstanceExpression/*?*/ genInst = qual.Qualifier as GenericTypeInstanceExpression; if (genInst != null) implementedInterfaces.Add(genInst); else implementedInterfaces.Add(new NamedTypeExpression(qual.Qualifier)); } } //if (badModifier) name.SourceContext.Document = null; //suppress any further errors involving this member switch (this.currentToken) { case Token.LeftBrace: case Token.This: this.ParseProperty(members, attributes, modifiers, type, implementedInterfaces, name, sctx, followers); return; case Token.LeftParenthesis: case Token.LessThan: this.ParseMethod(members, attributes, modifiers, type, implementedInterfaces, name, sctx, followers); return; default: if (implementedInterfaces != null) this.ParseMethod(members, attributes, modifiers, type, implementedInterfaces, name, sctx, followers); else this.ParseField(members, attributes, modifiers, type, name, sctx, followers); return; } }
/// <summary> /// A copy constructor that allocates an instance that is the same as the given template, except for its containing block. /// </summary> /// <param name="containingBlock">The containing block of the copied type invariant. This should be different from the containing block of the template.</param> /// <param name="template">The statement to copy.</param> protected TypeInvariant(BlockStatement containingBlock, TypeInvariant template) : base(containingBlock, template) { if (template.Name != null) this.name = template.Name.MakeCopyFor(containingBlock.Compilation); this.isAxiom = template.isAxiom; }
public VccFunctionTypeExpression(bool acceptsExtraArguments, CallingConvention callingConvention, TypeExpression returnType, NameDeclaration name, List<ParameterDeclaration> parameters, ISourceLocation sourceLocation) : base(sourceLocation) { this.AcceptsExtraArguments = acceptsExtraArguments; this.CallingConvention = callingConvention; this.ReturnType = returnType; this.Name = name; this.parameters = parameters; }