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);
        }
Esempio n. 2
0
        private ParseNodeList GetNamespaces(ParseNodeList members) {
            ParseNodeList namespaceList = new ParseNodeList();

            foreach (ParseNode memberNode in members) {
                NamespaceNode namespaceNode = memberNode as NamespaceNode;

                if (namespaceNode == null) {
                    // Top-level type nodes are turned into children of a namespace with
                    // an empty name.

                    Token nsToken = new Token(TokenType.Namespace, memberNode.Token.SourcePath, memberNode.Token.Position);
                    namespaceNode = new NamespaceNode(nsToken, String.Empty, _usingClauses, new ParseNodeList(memberNode));
                }

                namespaceList.Append(namespaceNode);
            }

            return namespaceList;
        }
Esempio n. 3
0
        private ParseNodeList GetNamespaces(ParseNodeList members)
        {
            ParseNodeList namespaceList = new ParseNodeList();

            foreach (ParseNode memberNode in members)
            {
                NamespaceNode namespaceNode = memberNode as NamespaceNode;

                if (namespaceNode == null)
                {
                    // Top-level type nodes are turned into children of a namespace with
                    // an empty name.

                    Token nsToken = new Token(TokenType.Namespace, memberNode.Token.SourcePath, memberNode.Token.Position);
                    namespaceNode = new NamespaceNode(nsToken, String.Empty, _usingClauses, new ParseNodeList(memberNode));
                }

                namespaceList.Append(namespaceNode);
            }

            return(namespaceList);
        }