Skip to content

Commit

Permalink
Merge pull request #1670 from pragmaware/improve-qt-header-parsing
Browse files Browse the repository at this point in the history
CXX: Improve qt header parsing
  • Loading branch information
pragmaware authored Jan 29, 2018
2 parents ecad395 + 322b7e8 commit 17d07a3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
9 changes: 9 additions & 0 deletions Units/parser-cxx.r/brackets.cpp.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
EMPTY_MACRO input.cpp /^#define EMPTY_MACRO$/;" macro file:
n01 input.cpp /^namespace n01 {$/;" namespace file:
g01 input.cpp /^ std::string g01 { "" };$/;" variable namespace:n01 typeref:typename:std::string
f01 input.cpp /^ auto f01(std::string p01) -> std::string {$/;" function namespace:n01 typeref:typename:std::string signature:(std::string p01)
Expand All @@ -14,3 +15,11 @@ C01 input.cpp /^ C01()$/;" function class:n01::C01 file: signature:()
l03 input.cpp /^ std::string l03 { "" };$/;" local function:n01::C01::C01 typeref:typename:std::string file:
l04 input.cpp /^ std::string l04 { "" };$/;" local function:n01::C01::C01 typeref:typename:std::string file:
l05 input.cpp /^ C01 l05{ "" };$/;" local function:n01::C01::C01 typeref:typename:C01 file:
f02 input.cpp /^ std::string f02() const EMPTY_MACRO { }$/;" function class:n01::C01 typeref:typename:std::string file: signature:() const
m04 input.cpp /^ int m04 { 0 };$/;" member class:n01::C01 typeref:typename:int file:
f03 input.cpp /^ std::string f03() const EMPTY_MACRO { }$/;" function class:n01::C01 typeref:typename:std::string file: signature:() const
f04 input.cpp /^ std::string f04() const EMPTY_MACRO { }$/;" function class:n01::C01 typeref:typename:std::string file: signature:() const
m05 input.cpp /^ int m05 { 0 };$/;" member class:n01::C01 typeref:typename:int file:
f05 input.cpp /^ std::string f05() const EMPTY_MACRO { }$/;" function class:n01::C01 typeref:typename:std::string file: signature:() const
f06 input.cpp /^ std::string f06() const { }$/;" function class:n01::C01 typeref:typename:std::string file: signature:() const
f07 input.cpp /^ std::string f07() { }$/;" function class:n01::C01 typeref:typename:std::string file: signature:()
13 changes: 13 additions & 0 deletions Units/parser-cxx.r/brackets.cpp.d/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <string>
#include <memory>

#define EMPTY_MACRO

namespace n01 {

std::string g01 { "" };
Expand Down Expand Up @@ -45,6 +47,17 @@ namespace n01 {
std::string l04 { "" };
C01 l05{ "" };
}

std::string f02() const EMPTY_MACRO { }
int m04 { 0 };

std::string f03() const EMPTY_MACRO { }
std::string f04() const EMPTY_MACRO { }
int m05 { 0 };

std::string f05() const EMPTY_MACRO { }
std::string f06() const { }
std::string f07() { }
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ l28 input.cpp /^ int l28 {};$/;" l function:main typeref:typename:int file:
l29 input.cpp /^ bool l29 { false };$/;" l function:main typeref:typename:bool file:
l30 input.cpp /^ std::string * l30{ new std::string("test") };$/;" l function:main typeref:typename:std::string * file:
l31 input.cpp /^ std::string * l31(new std::string("test"));$/;" l function:main typeref:typename:std::string * file:
l32 input.cpp /^ auto l32 = new std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >;$/;" l function:main typeref:typename:auto file:
m01 input.cpp /^ unsigned int m01;$/;" m struct:Struct1 typeref:typename:unsigned int file:
m02 input.cpp /^ std::string m02;$/;" m struct:Struct1 typeref:typename:std::string file:
m03 input.cpp /^ std::string ** m03, m04;$/;" m struct:Struct1 typeref:typename:std::string ** file:
Expand Down
2 changes: 2 additions & 0 deletions Units/parser-cxx.r/variable-declarations.cpp.d/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ int main(int argc,char ** argv)
std::string * l30{ new std::string("test") };
std::string * l31(new std::string("test"));

auto l32 = new std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >;

return 0;
}

Expand Down
24 changes: 19 additions & 5 deletions parsers/cxx/cxx_parser_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,28 @@ bool cxxParserParseBlockHandleOpeningBracket(void)
// Class::Class() : member { arg1, arg2, ... } { (4)
cxxTokenTypeIs(g_cxx.pToken->pPrev,CXXTokenTypeIdentifier) &&
(
// case 1
(!g_cxx.pToken->pPrev->pPrev) ||
(cxxTokenTypeIsOneOf(
// case 4
cxxTokenTypeIsOneOf(
g_cxx.pToken->pPrev->pPrev,
CXXTokenTypeIdentifier | CXXTokenTypeStar | CXXTokenTypeAnd |
CXXTokenTypeGreaterThanSign | CXXTokenTypeKeyword |
// FIXME: This check could be made stricter?
CXXTokenTypeSingleColon | CXXTokenTypeComma
))
) ||
// cases 1,2,3 but not 4
(
// more parts of typename or maybe the "new" keyword before the identifier
cxxTokenTypeIsOneOf(
g_cxx.pToken->pPrev->pPrev,
CXXTokenTypeIdentifier | CXXTokenTypeStar | CXXTokenTypeAnd |
CXXTokenTypeGreaterThanSign | CXXTokenTypeKeyword
) &&
// but no parenthesis (discard things like bool test() Q_DECL_NO_THROW { ... })
(!(pAux = cxxTokenChainPreviousTokenOfType(
g_cxx.pToken->pPrev->pPrev,
CXXTokenTypeParenthesisChain
))
)
)
) &&
// "override" is handled as identifier since it's a keyword only after function signatures
(strcmp(vStringValue(g_cxx.pToken->pPrev->pszWord),"override") != 0)
Expand Down
11 changes: 10 additions & 1 deletion parsers/cxx/cxx_parser_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,24 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF
CXXTokenTypeComma | CXXTokenTypeSemicolon | CXXTokenTypeOpeningBracket
))
{
// look for it, but also check for "<" signs: these usually indicate an uncondensed
// template. We give up on them as they are too complicated in this context.
// It's rather unlikely to have multiple declarations with templates after the first one
t = cxxTokenChainNextTokenOfType(
t,
CXXTokenTypeComma | CXXTokenTypeSemicolon | CXXTokenTypeOpeningBracket
CXXTokenTypeComma | CXXTokenTypeSemicolon | CXXTokenTypeOpeningBracket |
CXXTokenTypeSmallerThanSign
);
if(!t)
{
CXX_DEBUG_LEAVE_TEXT("Didn't find a comma, semicolon or {");
return bGotVariable;
}
if(cxxTokenTypeIs(t,CXXTokenTypeSmallerThanSign))
{
CXX_DEBUG_LEAVE_TEXT("Found '<': probably a template on the right side of declaration");
return bGotVariable;
}
}

if(cxxTokenTypeIsOneOf(t,CXXTokenTypeSemicolon | CXXTokenTypeOpeningBracket))
Expand Down

0 comments on commit 17d07a3

Please sign in to comment.