Commit 34641d6b authored by ussrhero's avatar ussrhero

fixed typeEval with const template arguments

parent 1126b00f
......@@ -981,18 +981,37 @@ std::string TypeEval::getNestedTemplateName(const parser::DoubleTemplateMatcher&
if (!templateName.empty())
templateName += ',';
templateName += templateMatcher.getNestedTemplateName();
auto nestedTemplate = templateMatcher.getNestedTemplateName();
templateName += '<';
nestedTemplate += '<';
templateName += getTemplateArgs(templateMatcher.getTemplateArgs2());
nestedTemplate += getTemplateArgs(templateMatcher.getTemplateArgs2());
if (nestedTemplate.back() == '>')
nestedTemplate += " >";
else
nestedTemplate += '>';
auto fullNestedTypeName = m_typeInfoProvider->makeTypeName(strToWStr(nestedTemplate), L"", templateMatcher.isNetstedTemplateConst());
templateName += wstrToStr(fullNestedTypeName);
templateName += " >";
templateName.insert(templateName.begin(), '<');
//templateName += templateMatcher.getNestedTemplateName();
if (templateName.back() == '>')
templateName.insert(templateName.end(), ' ');
//templateName += '<';
//templateName += getTemplateArgs(templateMatcher.getTemplateArgs2());
//templateName.insert(templateName.begin(), '<');
//if (templateName.back() == '>')
// templateName.insert(templateName.end(), ' ');
templateName += "> >";
//templateName += "> >";
return templateName;
}
......
......@@ -32,6 +32,21 @@ public:
}
};
class ConstMatcher : public Matcher
{
public:
MatchResult match(const TokenRange& matchRange)
{
auto matcher = all_of(
token_is(clang::tok::kw_const),
opt(rep(token_is(clang::tok::kw_const)))
);
return matchResult = matcher.match(matchRange);
}
};
class PointerMatcher : public Matcher
{
public:
......@@ -40,8 +55,7 @@ public:
{
auto matcher = all_of(
token_is(clang::tok::star),
opt(constMatcher),
opt(rep(token_is(clang::tok::kw_const)))
opt(constMatcher)
);
return matchResult = matcher.match(matchRange);
......@@ -54,7 +68,7 @@ public:
private:
Is<clang::tok::kw_const> constMatcher;
ConstMatcher constMatcher;
};
class PointerPointerMatcher : public Matcher
......@@ -403,6 +417,7 @@ public:
argsMatchers1
)
),
opt(constMatcher),
nestedTemplateName,
token_is(clang::tok::less),
opt(
......@@ -437,12 +452,19 @@ public:
return nestedTemplateName.getName();
}
bool isNetstedTemplateConst() const
{
assert(nestedTemplateName.getMatchResult().isMatched());
return constMatcher.getMatchResult().isMatched();
}
private:
ListMatcher<TemplateArgMatcher> argsMatchers1;
ListMatcher<TemplateArgMatcher> argsMatchers2;
CustomNameMatcher nestedTemplateName;
ConstMatcher constMatcher;
};
......@@ -565,7 +587,9 @@ public:
MatchResult match(const TokenRange& matchRange)
{
auto matcher = all_of(
opt(constMatcher1),
typeMatcher,
opt(constMatcher2),
opt(complexMatcher)
);
matchResult = matcher.match(matchRange);
......@@ -573,8 +597,10 @@ public:
}
bool isConst() const
{
return typeMatcher.isBasedType() && typeMatcher.getBaseTypeMatcher().isConst();
{
return constMatcher1.getMatchResult().isMatched() ||
constMatcher2.getMatchResult().isMatched() ||
(typeMatcher.isBasedType() && typeMatcher.getBaseTypeMatcher().isConst());
}
bool isBasedType() const
......@@ -620,6 +646,8 @@ public:
private:
ConstMatcher constMatcher1;
ConstMatcher constMatcher2;
TypeMatcher typeMatcher;
ComplexMatcher complexMatcher;
};
......
......@@ -75,6 +75,26 @@ TEST(TypeEvalTest, ConstBaseType)
EXPECT_THROW(evalType("const *"), TypeException);
}
TEST(TypeEvalTest, ConstStdTypesType)
{
EXPECT_EQ(L"UInt4B", evalType("const uint32_t")->getName());
EXPECT_EQ(L"UInt4B", evalType("uint32_t const const")->getName());
}
TEST(TypeEvalTest, ConstStuct)
{
static const char sourceCode[] = " \
struct TestStruct { \
}; \
TestStruct var1; \
";
TypeInfoProviderPtr typeProvider = getTypeInfoProviderFromSource(sourceCode);
EXPECT_EQ(L"TestStruct", evalType("const TestStruct", typeProvider)->getName());
EXPECT_EQ(L"TestStruct", evalType("const TestStruct const", typeProvider)->getName());
}
TEST(TypeEvalTest, Float)
{
EXPECT_EQ(L"Float", evalType("float")->getName());
......@@ -285,11 +305,16 @@ TEST(TypeEvalTest, TemplateNumeric)
TEST(TypeEvalTest, TemplateConst)
{
static const char sourceCode[] = " \
struct TestStruct { \
}; \
template<typename T1, typename...> \
struct TestStruct1 { \
}; \
TestStruct1<const int> val1; \
TestStruct1<const int,const char> val2; \
TestStruct1<const int,const char> val2; \
TestStruct1<const TestStruct> val3; \
TestStruct1<const TestStruct1<char> > val4; \
TestStruct1<const TestStruct1<char>, int> val5; \
";
TypeInfoProviderPtr typeProvider = getTypeInfoProviderFromSource(sourceCode);
......@@ -299,7 +324,11 @@ TEST(TypeEvalTest, TemplateConst)
EXPECT_EQ(L"TestStruct1<const int>", evalType("TestStruct1<const int const>", typeProvider)->getName());
EXPECT_EQ(L"TestStruct1<const int>", evalType("TestStruct1<const const int>", typeProvider)->getName());
EXPECT_EQ(L"TestStruct1<const int,const char>", evalType("TestStruct1<const int, const char>", typeProvider)->getName());
EXPECT_EQ(L"TestStruct1<const TestStruct>", evalType("TestStruct1<const TestStruct>", typeProvider)->getName());
EXPECT_EQ(L"TestStruct1<const TestStruct>", evalType("TestStruct1<TestStruct const>", typeProvider)->getName());
//EXPECT_EQ(L"TestStruct1<const TestStruct1<char>>", evalType("TestStruct1<const TestStruct1<char>>", typeProvider)->getName());
EXPECT_EQ(L"TestStruct1<const TestStruct1<char>,int>", evalType("TestStruct1<const TestStruct1<char>, int>", typeProvider)->getName());
EXPECT_THROW(evalType("TestStruct1<const>", typeProvider), TypeException);
EXPECT_THROW(evalType("TestStruct1<int, char>", typeProvider), TypeException);
}
......@@ -473,6 +502,8 @@ TEST(TypeEvalTest, TemplateClose)
}; \
TestStruct<int,TestStruct<int,int>> testVal1; \
TestStruct<int,TestStruct<int, TestStruct<int,int>>> testVal2; \
TestStruct<int,TestStruct<int,TestStruct<int,TestStruct<int,int>>>> testVal3; \
TestStruct<int,TestStruct<int,TestStruct<int,TestStruct<int,TestStruct<int,int>>>>> testVal4; \
";
TypeInfoProviderPtr typeProvider = getTypeInfoProviderFromSource(sourceCode);
......@@ -484,6 +515,8 @@ TEST(TypeEvalTest, TemplateClose)
EXPECT_NO_THROW(evalType("TestStruct<int,TestStruct<int,TestStruct<int,int>> >", typeProvider));
EXPECT_NO_THROW(evalType("TestStruct<int,TestStruct<int,TestStruct<int,int> >>", typeProvider));
EXPECT_NO_THROW(evalType("TestStruct<int,TestStruct<int,TestStruct<int,int> >>", typeProvider));
EXPECT_NO_THROW(evalType("TestStruct<int,TestStruct<int,TestStruct<int,TestStruct<int,int>>>>", typeProvider));
EXPECT_NO_THROW(evalType("TestStruct<int,TestStruct<int,TestStruct<int,TestStruct<int,TestStruct<int,int>>>>>", typeProvider));
}
TEST(TypeEvalTest, TemplateUnusedType)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment