Clang code completion - implementation

Is there any hidden documentation about how the clang code execution part is implemented? So far, I have found that a special token (tok :: code_completion) is entered into the lexer and processed in the parser. After observing such a token, the parser can fill in the possible completion lines.

What? I do not understand:
If the called function decides that we can insert a variable available in the current context. How is such a case handled?

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

The parser did not see the bar, but he really is for his call.

+4
source share
1 answer

As I can see, this is a common problem when analyzing method definitions within a structure and is not specific to code completion. In any case, in this case, special processing in the parser, which you can find in the file ParseCXXInlineMethods.cpp .

In a Parser::ParseCXXInlineMethodDef() comment:

 /// 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(... 

And later, the code for parsing method definitions:

 /// 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(... 

Thus, lexers created for function bodies are analyzed only after the rest of the class has been analyzed.

+4
source

Source: https://habr.com/ru/post/1490355/


All Articles