Ejemplo n.º 1
0
 /// <summary>
 /// Parses an #undef directive, starting at the character following "undef". 
 /// Updates this.preprocessorDefinedSymbols and adds a directive object to this.PreprocessorInformation.
 /// Leaves this.fragmentIndex pointing to the start of the current line. 
 /// </summary>
 /// <param name="include">True if the definition is part of an included block. If false, the directive is parsed but ignored.</param>
 private void ParseUndefine(bool include)
   //^ requires this.errorIndex < this.fragmentIndex;
   //^ requires this.fragmentIndex > this.startOfCurrentLine;
   //^ ensures this.startOfCurrentLine == this.fragmentIndex;
 {
   if (!this.allowPPDefinitions) {
     this.HandleError(Error.PPDefFollowsToken);
     this.SkipRestOfDirective();
     return;
   }
   if (!Scanner.IsBlankSpace(this.GetCurrentChar())) {
     this.errorIndex = this.fragmentIndex;
     this.SkipRestOfDirective();
     //^ assume this.fragmentIndex > this.errorIndex;
     this.HandleError(Error.ExpectedIdentifier);
     return;
   }
   string s = this.ScanIdentifier();
   //^ assert this.startOfCurrentLine <= this.fragmentIndex-s.Length; 
   if (s == "true" || s == "false") {
     //^ assume s.Length > 0;
     this.errorIndex = this.fragmentIndex-s.Length;
     this.HandleError(Error.ExpectedIdentifier);
     this.SkipRestOfDirective();
     return;
   }
   if (include) this.preprocessorDefinedSymbols.Remove(s);
   PreprocessorSymbol sym = new PreprocessorSymbol(s, this.GetSourceLocation(this.fragmentIndex-s.Length, s.Length));
   ISourceLocation loc = this.GetSourceLocation(this.startOfCurrentLine, this.fragmentIndex-this.startOfCurrentLine);
   //^ assume loc.Contains(sym.SourceLocation);
   this.preprocessorInformation.directives.Add(new UndefDirective(sym, loc));
   this.SkipPastBlanksCommentAndNewLine();
 }
Ejemplo n.º 2
0
 internal UndefDirective(PreprocessorSymbol definedSymbol, ISourceLocation sourceLocation)
   : base(sourceLocation) 
   // ^ requires sourceLocation.Contains(definedSymbol.SourceLocation);
 {
   this.definedSymbol = definedSymbol;
 }
Ejemplo n.º 3
0
 internal override Directive MakeShallowCopy(ISourceDocument newDocumentToPreprocess)
   //^^ requires newDocumentToPreprocess.IsUpdatedVersionOf(this.SourceLocation.SourceDocument);
 {
   ISourceLocation sloc = this.SourceLocation;
   //^ assume newDocumentToPreprocess.IsUpdatedVersionOf(sloc.SourceDocument); //follows from the precondition
   ISourceLocation dsloc = this.DefinedSymbol.SourceLocation;
   //^ assume sloc.Contains(dsloc); //follows from the preconditon of the constructor
   PreprocessorSymbol newSymbol = new PreprocessorSymbol(this.DefinedSymbol.Name, newDocumentToPreprocess.GetCorrespondingSourceLocation(dsloc));
   return new UndefDirective(newSymbol, newDocumentToPreprocess.GetCorrespondingSourceLocation(sloc));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Allocates an object that models a preprocessor #define directive.
 /// </summary>
 /// <param name="definedSymbol">The preprocessor symbol that is defined by this directive.</param>
 /// <param name="sourceLocation">The location in the source document where the #define directive appears.</param>
 internal DefineDirective(PreprocessorSymbol definedSymbol, ISourceLocation sourceLocation)
   : base(sourceLocation)
 {
   this.definedSymbol = definedSymbol;
 }