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);
        }
Beispiel #2
0
        internal void IncludeCompilationUnitUsingClauses()
        {
            CompilationUnitNode compilationUnit = (CompilationUnitNode)parent;

            if (compilationUnit.UsingClauses.Count != 0)
            {
                ParseNodeList mergedUsings = new ParseNodeList();
                mergedUsings.Append(compilationUnit.UsingClauses);

                if (_usingClauses.Count != 0)
                {
                    mergedUsings.Append(_usingClauses);
                }

                _usingClauses = GetParentedNodeList(mergedUsings);
            }
        }
Beispiel #3
0
        private CompilationUnitNode ParseCompilationUnit() {
            CompilationUnitNode tree
                = new CompilationUnitNode(
                    Eat(TokenType.BOF),
                    ParseExternAliases(),
                    ParseUsingClauses(),
                    ParseGlobalAttributes(),
                    ParseNamespaceMembers()
                    );
            Eat(TokenType.EOF);

            return tree;
        }