public CompilationUnitNode BuildCodeModel(IStreamSource source) { _hasErrors = false; string filePath = source.FullName; #if DEBUG if (_options.InternalTestMode) { // This ensures in file paths are just file names in test output. filePath = Path.GetFileName(filePath); } #endif // DEBUG char[] buffer = GetBuffer(source); if (buffer == null) { _errorHandler.ReportError("Unable to read from file " + filePath, filePath); return(null); } IDictionary definesTable = new Hashtable(); if ((_options.Defines != null) && (_options.Defines.Count != 0)) { foreach (string s in _options.Defines) { definesTable[s] = null; } } NameTable nameTable = new NameTable(); LineMap lineMap = new LineMap(filePath); FileLexer lexer = new FileLexer(nameTable, filePath); lexer.OnError += new FileErrorEventHandler(OnError); Token[] tokens = lexer.Lex(buffer, definesTable, lineMap, /* includeComments */ false); if (_hasErrors == false) { FileParser parser = new FileParser(nameTable, filePath); parser.OnError += new FileErrorEventHandler(OnError); CompilationUnitNode compilationUnit = parser.Parse(tokens, lineMap); foreach (ParseNode node in compilationUnit.Members) { NamespaceNode namespaceNode = node as NamespaceNode; if (namespaceNode != null) { namespaceNode.IncludeCompilationUnitUsingClauses(); } } if (_hasErrors == false) { return(compilationUnit); } } return(null); }
public CompilationUnitNode BuildCodeModel(IStreamSource source) { hasErrors = false; string filePath = source.FullName; char[] buffer = GetBuffer(source); if (buffer == null) { errorHandler.ReportInputError(filePath); return(null); } IDictionary definesTable = new Hashtable(); if (options.Defines != null && options.Defines.Count != 0) { foreach (string s in options.Defines) { definesTable[s] = null; } } NameTable nameTable = new NameTable(); LineMap lineMap = new LineMap(filePath); FileLexer lexer = new FileLexer(nameTable, filePath); lexer.OnError += OnError; Token[] tokens = lexer.Lex(buffer, definesTable, lineMap, /* includeComments */ false); if (hasErrors == false) { FileParser parser = new FileParser(nameTable, filePath); parser.OnError += OnError; CompilationUnitNode compilationUnit = parser.Parse(tokens, lineMap); foreach (ParseNode node in compilationUnit.Members) { if (node is NamespaceNode namespaceNode) { namespaceNode.IncludeCompilationUnitUsingClauses(); } } if (hasErrors == false) { return(compilationUnit); } } return(null); }