2013-07-08 35 views
4

是否有一些隱藏的文檔clang的代碼完成部分是如何實現的?到目前爲止,我發現的是,特殊標記(tok :: code_completion)被注入詞法分析器並在解析器中處理。在觀察這樣的標記之後,解析器可以填充可能的完成字符串。鐺代碼完成 - 實現設計

我不明白:
如果被調用的功能決定我們可以插入一個當前上下文中可用的變量。這種情況如何處理?

struct FooBar { 
    void foo() { 
     ba<<code completion here>> 
    } 
    void bar() { 
    } 
}; 

解析器還沒有看到吧,但它是有效的調用它。

回答

4

正如我所看到的,這是解析結構內部的方法定義時的一個普遍問題,並且不是特定於代碼完成。無論如何,在這種情況下,解析器中有特殊的處理,您可以在the ParseCXXInlineMethods.cpp file中找到它。

從評論Parser::ParseCXXInlineMethodDef()

/// ParseCXXInlineMethodDef - We parsed and verified that the specified 
/// Declarator is a well formed C++ inline method definition. Now lex its body 
/// and store its tokens for parsing after the C++ class is complete. 
Parser::DeclPtrTy 
Parser::ParseCXXInlineMethodDef(... 

後來,解析方法定義代碼:

/// ParseLexedMethodDefs - We finished parsing the member specification of a top 
/// (non-nested) C++ class. Now go over the stack of lexed methods that were 
/// collected during its parsing and parse them all. 
void Parser::ParseLexedMethodDefs(... 

因此詞法分析器生成令牌的函數體後剩下的只是解析的類被解析。

+0

感謝您的回答 - 清理了一些東西 – Daniel