MCPcopy Create free account
hub / github.com/KDAB/codebrowser / parseDeclarationReference

Function parseDeclarationReference

generator/commenthandler.cpp:39–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37#include <iostream>
38
39clang::NamedDecl *parseDeclarationReference(llvm::StringRef Text, clang::Sema &Sema, bool isFunction) {
40
41 clang::Preprocessor &PP = Sema.getPreprocessor();
42
43 auto Buf = llvm::MemoryBuffer::getMemBufferCopy(Text);
44 llvm::MemoryBuffer *Buf2 = &*Buf;
45#if CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR <= 4
46 auto FID = PP.getSourceManager().createFileIDForMemBuffer(Buf);
47#else
48 auto FID = PP.getSourceManager().createFileID(std::move(Buf));
49#endif
50 clang::Lexer Lex(FID, Buf2, PP.getSourceManager(), PP.getLangOpts());
51
52 auto TuDecl = Sema.getASTContext().getTranslationUnitDecl();
53 clang::CXXScopeSpec SS;
54 clang::Token Tok, Next;
55 Lex.LexFromRawLexer(Tok);
56
57 for (; !Tok.is(clang::tok::eof); Tok = Next) {
58 Lex.LexFromRawLexer(Next);
59 clang::IdentifierInfo* II = nullptr;
60 if (Tok.is(clang::tok::raw_identifier)) {
61 II = PP.LookUpIdentifierInfo(Tok);
62 }
63
64 if (Tok.is(clang::tok::coloncolon)) {
65 SS.MakeGlobal(Sema.getASTContext(), Tok.getLocation());
66 continue;
67 } else if (Tok.is(clang::tok::identifier)) {
68
69 if (Next.is(clang::tok::coloncolon)) {
70
71 clang::Sema::TemplateTy Template;
72 clang::UnqualifiedId Name;
73 Name.setIdentifier(II, Tok.getLocation());
74 bool dummy;
75 auto TemplateKind = Sema.isTemplateName(Sema.getScopeForContext(TuDecl), SS, false, Name, {}, false, Template, dummy);
76 if (TemplateKind == clang::TNK_Non_template) {
77#if CLANG_VERSION_MAJOR >= 4
78 clang::Sema::NestedNameSpecInfo nameInfo(II, Tok.getLocation(), Next.getLocation());
79 if (Sema.ActOnCXXNestedNameSpecifier(Sema.getScopeForContext(TuDecl), nameInfo , false, SS))
80#else
81 if (Sema.ActOnCXXNestedNameSpecifier(Sema.getScopeForContext(TuDecl), *II, Tok.getLocation(), Next.getLocation(), {}, false, SS))
82#endif
83 {
84 SS.SetInvalid(Tok.getLocation());
85 }
86 } else if (auto T = Template.get().getAsTemplateDecl()) {
87 // FIXME: For template, it is a bit tricky
88 // It is still a bit broken but works in some cases for most normal functions
89 auto T2 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>(T->getTemplatedDecl());
90 if (T2) {
91 Lex.LexFromRawLexer(Tok);
92 if (!Tok.is(clang::tok::raw_identifier))
93 return nullptr;
94 II = PP.LookUpIdentifierInfo(Tok);
95 Lex.LexFromRawLexer(Next);
96 if (!Next.is(clang::tok::eof) && !Next.is(clang::tok::l_paren))

Callers 1

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected