Exemple #1
0
 //^^ requires newDocumentToPreprocess.IsUpdatedVersionOf(this.SourceLocation.SourceDocument);
 internal override Directive MakeShallowCopy(ISourceDocument newDocumentToPreprocess)
 {
     ISourceLocation sloc = this.SourceLocation;
       //^ assume newDocumentToPreprocess.IsUpdatedVersionOf(sloc.SourceDocument); //follows from the precondition
       //unsatisfied precondition: requires this.IsUpdatedVersionOf(sourceLocationInPreviousVersionOfDocument.SourceDocument);
       IfDirective result = new IfDirective(this.Condition, newDocumentToPreprocess.GetCorrespondingSourceLocation(sloc));
       foreach (ElifPart elifPart in this.Elifs)
     result.elifs.Add(new ElifPart(elifPart.Condition, newDocumentToPreprocess.GetCorrespondingSourceLocation(elifPart.SourceLocation)));
       if (this.Else != null)
     result.@else = new ElsePart(newDocumentToPreprocess.GetCorrespondingSourceLocation(this.Else.SourceLocation));
       if (this.Endif != null)
     result.endif = new EndifPart(newDocumentToPreprocess.GetCorrespondingSourceLocation(this.Endif.SourceLocation));
       return result;
 }
Exemple #2
0
 /// <summary>
 /// Parses the #if part of an #if-#elif-#else-#endif construct, starting at the character following "if". 
 /// Adds a corresponding IfDirective instance to this.preprocesorInformation.
 /// Leaves this.fragmentIndex pointing to the start of the first line after the matching #endif directive.
 /// Returns all source locations that are to be included in the preprocessor output. (No locations are returned if the include parameter is false.)
 /// </summary>
 /// <param name="include">True if the directive is part of an included block. If false, the directive is parsed but ignored. (No locations are returned.)</param>
 private IEnumerable<ISourceLocation> ParseIf(bool include)
 {
     SourceLocationBuilder slb = new SourceLocationBuilder(this.GetSourceLocation(this.startOfCurrentLine, this.fragmentIndex-this.startOfCurrentLine));
       PreprocessorExpression condition = this.ParseExpression();
       IfDirective ifDirective = new IfDirective(condition, slb);
       this.preprocessorInformation.directives.Add(ifDirective);
       this.SkipPastBlanksCommentAndNewLine();
       bool allowElseToInclude = include;
       if (include) {
     include = condition.IsDefined(this.preprocessorDefinedSymbols);
     if (include)
       allowElseToInclude = false;
       }
       foreach (ISourceLocation includedSourceFragment in this.ParseSection(true, true, false, include, allowElseToInclude))
     yield return includedSourceFragment;
       slb.UpdateToSpan(this.GetSourceLocation(this.fragmentIndex-1, 0));
 }