private int startOfCurrentLine; //^ invariant 0 <= startOfCurrentLine && startOfCurrentLine <= fragmentIndex; #endregion Fields #region Constructors /// <summary> /// Allocates a preprocessor instance that can be queried for a list of source locations that represent the output from the preprocessor. This output /// omits preprocessor directives as well as any excluded sections. It also applies line directives by mapping some of the produced source locations /// onto the documents mentioned in the line directives. In other words, the produced source locations will not necessarily come from the document /// being preprocessed. Preprocessing happens lazily when the result of calling GetIncludedSections is enumerated. /// </summary> /// <param name="documentToProcess">The source document to preprocess.</param> /// <param name="options">An object that specifies any preprocessor symbols that are defined as compiler options by the environment.</param> internal Preprocessor(IVccUnpreprocessedSourceDocument documentToProcess, VccOptions options) { this.documentToProcess = documentToProcess; List<IErrorMessage> errors = this.errors = new List<IErrorMessage>(); this.preprocessorInformation = new PreprocessorInformation(documentToProcess, errors); Dictionary<string, string> preprocessorDefinedSymbols = new Dictionary<string,string>(); foreach (string ppOption in options.PreprocessorOptions) { if (!ppOption.StartsWith("/D", StringComparison.Ordinal)) continue; int eqIndex = ppOption.IndexOf('='); if (eqIndex < 0) eqIndex = ppOption.Length; string symName = ppOption.Substring(2, eqIndex-2); preprocessorDefinedSymbols[symName] = eqIndex != ppOption.Length ? ppOption.Substring(eqIndex+1) : String.Empty; } preprocessorDefinedSymbols["true"] = "true"; preprocessorDefinedSymbols.Remove("false"); this.preprocessorDefinedSymbols = preprocessorDefinedSymbols; this.buffer = new char[8192]; }
internal Preprocessor(IVccUnpreprocessedSourceDocument documentToProcess, IDictionary<string, string> preprocessorDefinedSymbols, List<IErrorMessage> errors) { this.documentToProcess = documentToProcess; this.preprocessorDefinedSymbols = preprocessorDefinedSymbols; this.errors = errors; this.preprocessorInformation = new PreprocessorInformation(documentToProcess, errors); this.buffer = new char[8192]; }
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; }