Commit 66861991 authored by ussrhero's avatar ussrhero

fixed problem with const in templates

parent d2f918fd
......@@ -182,6 +182,7 @@ class TypeInfoProvider
public:
virtual TypeInfoPtr getTypeByName(const std::wstring& name) = 0;
virtual TypeInfoEnumeratorPtr getTypeEnumerator(const std::wstring& mask = L"") = 0;
virtual std::wstring makeTypeName(const std::wstring& typeName, const std::wstring& qualified, bool const) = 0;
};
class TypeInfoEnumerator {
......
......@@ -935,117 +935,5 @@ MatchResult BaseTypeMatcher::match(const TokenRange& matchRange)
}
std::string BaseTypeMatcher::getTypeName() const
{
std::string name;
if (m_const)
name += "const ";
name += m_typeName;
return name;
}
TypeInfoPtr BaseTypeMatcher::getBaseType() const
{
return m_typeInfo;
}
//TypeInfoPtr TypeEval::getBaseType()
//{
// if (m_tokens->front().is(clang::tok::kw_void))
// {
// m_tokens->pop_front();
// return loadType(L"Void");
// }
//
// std::unique_ptr<BaseTypeBuilder> baseTypeBuilder(new EmptyBaseTypeBuilder);
//
// while (true)
// {
// auto token = m_tokens->front();
//
// if (token.is(m_endToken))
// break;
//
// if (token.is(clang::tok::kw_int))
// {
// baseTypeBuilder.reset(baseTypeBuilder->addInt());
// m_tokens->pop_front();
// continue;
// }
//
// if (token.is(clang::tok::kw_char))
// {
// baseTypeBuilder.reset(baseTypeBuilder->addChar());
// m_tokens->pop_front();
// continue;
// }
//
// if (token.is(clang::tok::kw_short))
// {
// baseTypeBuilder.reset(baseTypeBuilder->addShort());
// m_tokens->pop_front();
// continue;
// }
//
// if (token.is(clang::tok::kw_unsigned))
// {
// baseTypeBuilder.reset(baseTypeBuilder->addUnsigned());
// m_tokens->pop_front();
// continue;
// }
//
// if (token.is(clang::tok::kw_signed))
// {
// baseTypeBuilder.reset(baseTypeBuilder->addSigned());
// m_tokens->pop_front();
// continue;
// }
//
// if (token.is(clang::tok::kw_long))
// {
// baseTypeBuilder.reset(baseTypeBuilder->addLong());
// m_tokens->pop_front();
// continue;
// }
//
// if (isInt64KeyWord(token))
// {
// baseTypeBuilder.reset(baseTypeBuilder->addLong());
// baseTypeBuilder.reset(baseTypeBuilder->addLong());
// m_tokens->pop_front();
// continue;
// }
//
// if (token.is(clang::tok::kw_float))
// {
// baseTypeBuilder.reset(baseTypeBuilder->addFloat());
// m_tokens->pop_front();
// continue;
// }
//
// if (token.is(clang::tok::kw_double))
// {
// baseTypeBuilder.reset(baseTypeBuilder->addDouble());
// m_tokens->pop_front();
// continue;
// }
//
// if (token.is(clang::tok::kw_const))
// {
// m_tokens->pop_front();
// continue;
// }
//
// if (token.isOneOf(clang::tok::star, clang::tok::l_paren, clang::tok::l_square,
// clang::tok::amp, clang::tok::ampamp))
// break;
//
// throw ExprException(L"error syntax");
// }
//
// return baseTypeBuilder->getResult();
//}
}
}
\ No newline at end of file
......@@ -17,9 +17,20 @@ public:
MatchResult match(const TokenRange& matchRange);
std::string getTypeName() const;
TypeInfoPtr getBaseType() const;
std::string getTypeName() const
{
return m_typeName;
}
TypeInfoPtr getBaseType() const
{
return m_typeInfo;
}
bool isConst() const
{
return m_const;
}
private:
......
......@@ -868,6 +868,23 @@ TypeInfoEnumeratorPtr TypeInfoProviderClang::getTypeEnumerator(const std::wstrin
///////////////////////////////////////////////////////////////////////////////
std::wstring TypeInfoProviderClang::makeTypeName(const std::wstring& typeName, const std::wstring& typeQualifier, bool isConst)
{
std::wstringstream wstr;
if (isConst)
wstr << L"const ";
wstr << typeName;
if (!typeQualifier.empty())
wstr << L' ' << typeQualifier;
return wstr.str();
}
///////////////////////////////////////////////////////////////////////////////
TypeInfoProviderClangEnum::TypeInfoProviderClangEnum(const std::wstring& mask, const boost::shared_ptr<TypeInfoProviderClang>& clangProvider )
{
m_index = 0;
......
......@@ -388,9 +388,11 @@ public:
private:
virtual TypeInfoPtr getTypeByName(const std::wstring& name);
TypeInfoPtr getTypeByName(const std::wstring& name) override;
virtual TypeInfoEnumeratorPtr getTypeEnumerator(const std::wstring& mask);
TypeInfoEnumeratorPtr getTypeEnumerator(const std::wstring& mask) override;
std::wstring makeTypeName(const std::wstring& typeName, const std::wstring& typeQualifier, bool isConst) override;
private:
......
......@@ -1069,21 +1069,17 @@ TypeInfoPtr TypeEval::getCustomType(const parser::CustomTypeMatcher& customMatc
std::string TypeEval::getTypeName(const parser::QualifiedTypeMatcher& typeMatcher)
{
std::string typeName;
if (typeMatcher.isConst())
{
typeName = "const ";
}
std::string typeName;
std::string typeQualifier;
if (typeMatcher.isBasedType())
{
typeName += typeMatcher.getBaseTypeMatcher().getTypeName();
typeName = typeMatcher.getBaseTypeMatcher().getTypeName();
}
else
if (typeMatcher.isCustomType())
{
typeName += getCustomTypeName(typeMatcher.getCustomMatcher());
typeName = getCustomTypeName(typeMatcher.getCustomMatcher());
}
else
{
......@@ -1091,12 +1087,13 @@ std::string TypeEval::getTypeName(const parser::QualifiedTypeMatcher& typeMatche
}
if (typeMatcher.isComplexType())
{
typeName += ' ';
typeName += getTypeModifierRecursive(typeMatcher.getComplexMather());
}
{
typeQualifier = getTypeModifierRecursive(typeMatcher.getComplexMather());
}
return typeName;
auto fullTypeName = m_typeInfoProvider->makeTypeName(strToWStr(typeName), strToWStr(typeQualifier), typeMatcher.isConst());
return wstrToStr(fullTypeName);
}
///////////////////////////////////////////////////////////////////////////////
......
......@@ -574,8 +574,7 @@ public:
bool isConst() const
{
// return (typeMatcher.isBasedType() && typeMatcher.getBaseTypeMatcher().isConst());
return false;
return typeMatcher.isBasedType() && typeMatcher.getBaseTypeMatcher().isConst();
}
bool isBasedType() const
......
#include "stdafx.h"
#include <set>
#include <boost/regex.hpp>
#include <regex>
#include "kdlib/memaccess.h"
#include "kdlib/exceptions.h"
......@@ -652,7 +652,51 @@ ScopePtr ModuleImp::getScope()
return ScopePtr(new ModuleScope(shared_from_this()));
}
///////////////////////////////////////////////////////////////////////////////
//static const std::wregex constMatch(L"[<,](const\\s)([^,>]*)[,>]");
//
//TypeInfoPtr ModuleImp::getTypeByName(const std::wstring &typeName)
//{
// try
// {
// return loadType(getSymbolScope(), typeName);
// }
// catch (SymbolException& symExc)
// {
// if (typeName.find(L"const") == std::wstring::npos)
// {
// throw symExc;
// }
// }
//
// // template<const int, int> in pdb symbols will be looks like template<int const ,int>
// // it is may be bug, but we can fix it
//
// //std::wsmatch matchResult;
//
// //auto current = typeName.cbegin();
// //auto end = typeName.cend();
//
// //std::wstring typeName1;
//
// //while (std::regex_search(current, end, matchResult, constMatch))
// //{
// // typeName1.insert(typeName1.end(), current, matchResult[1].first);
// // typeName1.insert(typeName1.end(), matchResult[2].first, matchResult[2].second);
// // typeName1.insert(typeName1.size(), L" const ");
//
// // current = matchResult[2].second;
// //}
//
// //if (current != end)
// //{
// // typeName1.insert(typeName1.end(), current, end);
// //}
//
// return loadType(getSymbolScope(), typeName1);
//
//}
///////////////////////////////////////////////////////////////////////////////
MEMOFFSET_64 findModuleBySymbol( const std::wstring &symbolName )
......@@ -730,13 +774,13 @@ void getSourceLine( std::wstring &fileName, unsigned long &lineno, long &displac
///////////////////////////////////////////////////////////////////////////////
static const boost::wregex moduleSymMatch(L"^(?:([^!]*)!)?([^!]+)$");
static const std::wregex moduleSymMatch(L"^(?:([^!]*)!)?([^!]+)$");
void splitSymName( const std::wstring &fullName, std::wstring &moduleName, std::wstring &symbolName )
{
boost::wsmatch matchResult;
std::wsmatch matchResult;
if ( !boost::regex_match( fullName, matchResult, moduleSymMatch ) )
if ( !std::regex_match( fullName, matchResult, moduleSymMatch ) )
{
std::wstringstream sstr;
sstr << L"invalid symbol name: " << fullName;
......@@ -757,4 +801,5 @@ void splitSymName( const std::wstring &fullName, std::wstring &moduleName, std::
///////////////////////////////////////////////////////////////////////////////
}; // kdlib namespace end
......@@ -246,12 +246,12 @@ protected:
class ModuleImp : public ModuleBaseImp, public boost::enable_shared_from_this<ModuleImp> {
friend ModulePtr loadModule( MEMOFFSET_64 offset );
friend ModulePtr loadModule(MEMOFFSET_64 offset);
protected:
explicit ModuleImp( MEMOFFSET_64 offset );
explicit ModuleImp(MEMOFFSET_64 offset);
protected:
......@@ -299,10 +299,10 @@ protected:
std::wstring getSymFile();
void
reloadSymbols();
reloadSymbols();
void
resetSymbols()
resetSymbols()
{
m_symSession.reset();
}
......@@ -312,23 +312,23 @@ protected:
return !m_exportSymbols && !m_noSymbols;
}
MEMOFFSET_64 getSymbolVa( const std::wstring &symbolName );
MEMOFFSET_32 getSymbolRva( const std::wstring &symbolName );
MEMOFFSET_64 getSymbolVa(const std::wstring &symbolName);
MEMOFFSET_32 getSymbolRva(const std::wstring &symbolName);
SymbolPtr getSymbolByVa( MEMOFFSET_64 offset, MEMDISPLACEMENT* displacement = 0 );
SymbolPtr getSymbolByVa( MEMOFFSET_64 offset, unsigned long symTag, MEMDISPLACEMENT* displacement );
SymbolPtr getSymbolByRva( MEMOFFSET_32 offset, MEMDISPLACEMENT* displacement = 0 );
SymbolPtr getSymbolByRva( MEMOFFSET_32 offset, unsigned long symTag, MEMDISPLACEMENT* displacement );
SymbolPtr getSymbolByVa(MEMOFFSET_64 offset, MEMDISPLACEMENT* displacement = 0);
SymbolPtr getSymbolByVa(MEMOFFSET_64 offset, unsigned long symTag, MEMDISPLACEMENT* displacement);
SymbolPtr getSymbolByRva(MEMOFFSET_32 offset, MEMDISPLACEMENT* displacement = 0);
SymbolPtr getSymbolByRva(MEMOFFSET_32 offset, unsigned long symTag, MEMDISPLACEMENT* displacement);
SymbolPtr getSymbolByName( const std::wstring &symbolName );
SymbolPtr getSymbolByName(const std::wstring &symbolName);
SymbolPtr getSymbolScope();
size_t getSymbolSize( const std::wstring &symName );
size_t getSymbolSize(const std::wstring &symName);
TypeInfoPtr getTypeByName( const std::wstring &typeName ) {
return loadType( getSymbolScope(), typeName );
TypeInfoPtr getTypeByName(const std::wstring &typeName)
{
return loadType(getSymbolScope(), typeName);
}
TypedVarPtr getTypedVarByAddr( MEMOFFSET_64 offset );
......
......@@ -759,11 +759,7 @@ TypeInfoPtr TypeInfo::getTypeInfoFromCache(const std::wstring &typeName)
MEMOFFSET_64 moduleOffset = findModuleBySymbol(typeName);
ModulePtr module = loadModule(moduleOffset);
SymbolPtr symbolScope = module->getSymbolScope();
TypeInfoPtr typeInfo = loadType(symbolScope, typeName);
TypeInfoPtr typeInfo = loadModule(moduleOffset)->getTypeByName(typeName);;
ProcessMonitor::insertTypeInfo(typeInfo);
......@@ -2102,6 +2098,40 @@ TypeInfoEnumeratorPtr TypeInfoSymbolProvider::getTypeEnumerator(const std::wstri
///////////////////////////////////////////////////////////////////////////////
std::wstring TypeInfoSymbolProvider::makeTypeName(const std::wstring& typeName, const std::wstring& typeQualifier, bool isConst)
{
std::wstringstream wstr;
wstr << typeName;
if (!typeQualifier.empty())
wstr << L' ' << typeQualifier;
if (isConst)
wstr << L" const ";
return wstr.str();
}
///////////////////////////////////////////////////////////////////////////////
std::wstring TypeInfoDefaultProvider::makeTypeName(const std::wstring& typeName, const std::wstring& typeQualifier, bool isConst)
{
std::wstringstream wstr;
wstr << typeName;
if (!typeQualifier.empty())
wstr << L' ' << typeQualifier;
if (isConst)
wstr << L" const ";
return wstr.str();
}
///////////////////////////////////////////////////////////////////////////////
inline
bool isTypeTag(SymTags tag)
{
......
......@@ -1110,10 +1110,6 @@ protected:
size_t m_count;
};
///////////////////////////////////////////////////////////////////////////////
class TypeInfoSymbolArray : public TypeInfoArray
......@@ -1163,9 +1159,11 @@ public:
private:
virtual TypeInfoPtr getTypeByName(const std::wstring& name);
TypeInfoPtr getTypeByName(const std::wstring& name) override;
TypeInfoEnumeratorPtr getTypeEnumerator(const std::wstring& mask = L"") override;
virtual TypeInfoEnumeratorPtr getTypeEnumerator(const std::wstring& mask = L"");
std::wstring makeTypeName(const std::wstring& typeName, const std::wstring& typeQualifier, bool isConst) override;
private:
......@@ -1187,6 +1185,8 @@ class TypeInfoDefaultProvider : public TypeInfoProvider
{
throw TypeException(L"failed to enumrate types");
}
std::wstring makeTypeName(const std::wstring& typeName, const std::wstring& typeQualifier, bool isConst) override;
};
......
......@@ -439,3 +439,9 @@ TEST_F(ExprEvalTarget, Eval1)
EXPECT_EQ( (g_testArray + 1)->m_field1 % 4, evalExpr("(g_testArray + 1)->m_field1 % 4", m_targetModule->getScope()));
}
TEST_F(ExprEvalTarget, TemplateConstCast)
{
TypedValue evalResult;
ASSERT_NO_THROW(evalResult = evalExpr("(std::_Compressed_pair<std::allocator<std::_Tree_node<std::pair<const int, TemplateStruct<int> >, void *> >, std::_Tree_val<std::_Tree_simple_types<std::pair<const int, TemplateStruct<int> > > >, 1>*)nullptr"));
}
......@@ -709,4 +709,5 @@ TEST_F(TypeInfoTest, isInheritedMember)
EXPECT_FALSE(typeInfo->isInheritedMember(typeInfo->getElementIndex(L"m_staticConst")));
EXPECT_TRUE(typeInfo->isInheritedMember(typeInfo->getElementIndex(L"m_baseField")));
EXPECT_THROW(loadType(L"Int8B[]")->isInheritedMember(0), TypeException);
}
\ No newline at end of file
}
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