/// <summary> /// Parses a #line directive, starting at the character following "line". /// Adds a LineDirective instance to this.preprocesorInformation. /// Leaves this.fragmentIndex pointing to the start of the first line after the line containing the #line directive. /// </summary> private void ParseLine(bool include) //^ requires this.fragmentIndex > 0; //^ ensures this.startOfCurrentLine == this.fragmentIndex; { this.SkipBlanks(); int? lineNumber = null; string/*?*/ documentName = null; string docName; this.errorIndex = this.fragmentIndex; char c = this.GetCurrentChar(); if (c == 'd') { string d = this.ScanDirective(); if (d != "default") { //^ assume this.fragmentIndex > this.errorIndex; this.HandleError(Error.PPDirectiveExpected); } this.sourceOfInclusion = null; } else { if (!Scanner.IsDigit(c)) { if (this.fragmentIndex == this.fragmentLength) this.errorIndex = fragmentIndex -1; else this.fragmentIndex++; this.HandleError(Error.InvalidLineNumber); } else lineNumber = this.originalLineNumber = this.ScanNumber(); } this.SkipBlanks(); if (this.GetCurrentChar() == '"') { documentName = docName = this.ScanString(); } else { docName = this.documentToProcess.Name.Value; if (this.sourceOfInclusion != null) docName = this.sourceOfInclusion.Name.Value; } if (include) { //^ assume this.fragmentIndex > this.startOfCurrentLine; LineDirective lineDirective = new LineDirective(lineNumber, documentName, this.GetSourceLocation(this.startOfCurrentLine, this.fragmentIndex-this.startOfCurrentLine)); this.preprocessorInformation.directives.Add(lineDirective); } //^ assume this.fragmentIndex <= this.fragmentLength; this.SkipPastBlanksCommentAndNewLine(); this.sourceOfInclusion = new SourceDocumentWithInclusion(this.documentToProcess, this.originalLineNumber, docName, this.offset+this.startOfCurrentLine); }
internal PreprocessorInformation(IPrimarySourceDocument newDocumentToPreprocess, PreprocessorInformation template) { this.sourceDocument = newDocumentToPreprocess; SourceDocumentWithInclusion/*?*/ sourceOfInclusion = null; List<Directive> directives = new List<Directive>(template.Directives); List<IErrorMessage> errors = new List<IErrorMessage>(template.errors); List<ISourceLocation> excludedLocations = new List<ISourceLocation>(template.ExcludedLocations); List<ISourceLocation> includedLocations = new List<ISourceLocation>(template.IncludedLocations); for (int i = 0, n = directives.Count; i < n; i++) { //^ assume newDocumentToPreprocess.IsUpdatedVersionOf(directives[i].SourceLocation.SourceDocument); directives[i] = directives[i].MakeShallowCopy(newDocumentToPreprocess); } for (int i = 0, n = errors.Count; i < n; i++) { ISourceErrorMessage/*?*/ sourceError = errors[i] as ISourceErrorMessage; //^ assume sourceError != null; //^ assume newDocumentToPreprocess.IsUpdatedVersionOf(sourceError.SourceLocation.SourceDocument); errors[i] = sourceError.MakeShallowCopy(newDocumentToPreprocess); } for (int i = 0, n = excludedLocations.Count; i < n; i++) { ISourceLocation excludedLocation = excludedLocations[i]; SourceDocumentWithInclusion/*?*/ idoc = excludedLocation.SourceDocument as SourceDocumentWithInclusion; if (idoc != null) { if (sourceOfInclusion == null || !idoc.IsUpdatedVersionOf(sourceOfInclusion)) sourceOfInclusion = new SourceDocumentWithInclusion(newDocumentToPreprocess, idoc.OriginalLineNumber, idoc.OriginalDocumentName, idoc.StartingPositionOfIncludedRegion); excludedLocations[i] = sourceOfInclusion.GetCorrespondingSourceLocation(excludedLocation); } else { //^ assume newDocumentToPreprocess.IsUpdatedVersionOf(excludedLocation.SourceDocument); excludedLocations[i] = newDocumentToPreprocess.GetCorrespondingSourceLocation(excludedLocation); } } for (int i = 0, n = includedLocations.Count; i < n; i++) { ISourceLocation includedLocation = includedLocations[i]; SourceDocumentWithInclusion/*?*/ idoc = includedLocation.SourceDocument as SourceDocumentWithInclusion; if (idoc != null) { if (sourceOfInclusion == null || !idoc.IsUpdatedVersionOf(sourceOfInclusion)) sourceOfInclusion = new SourceDocumentWithInclusion(newDocumentToPreprocess, idoc.OriginalLineNumber, idoc.OriginalDocumentName, idoc.StartingPositionOfIncludedRegion); includedLocations[i] = sourceOfInclusion.GetCorrespondingSourceLocation(includedLocation); } else { //^ assume newDocumentToPreprocess.IsUpdatedVersionOf(includedLocation.SourceDocument); includedLocations[i] = newDocumentToPreprocess.GetCorrespondingSourceLocation(includedLocation); } } this.directives = directives; this.errors = errors; this.excludedLocations = excludedLocations; this.includedLocations = includedLocations; }