mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-17 07:13:27 +02:00
merge CppParser C++11 and other improvements from appinf
This commit is contained in:
parent
03f22ded65
commit
cc664cba89
@ -77,6 +77,9 @@ public:
|
||||
void typeDefs(SymbolTable& table) const;
|
||||
/// Fills the symbol table with all type definitions.
|
||||
|
||||
void typeAliases(SymbolTable& table) const;
|
||||
/// Fills the symbol table with all type alias (using) definitions.
|
||||
|
||||
void enums(SymbolTable& table) const;
|
||||
/// Fills the symbol table with all enums.
|
||||
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
SYM_PARAMETER, /// A function parameter
|
||||
SYM_STRUCT, /// A struct or class
|
||||
SYM_TYPEDEF, /// A typedef
|
||||
SYM_TYPEALIAS, /// A type alias (using)
|
||||
SYM_BUILTIN, /// A built-in type
|
||||
SYM_VARIABLE /// A (member) variable
|
||||
};
|
||||
|
@ -43,6 +43,23 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class CppParser_API TypeAlias: public Decl
|
||||
/// This class represents a type alias definition (using).
|
||||
{
|
||||
public:
|
||||
TypeAlias(const std::string& decl, NameSpace* pNameSpace);
|
||||
/// Creates the TypeAlias.
|
||||
|
||||
~TypeAlias();
|
||||
/// Destroys the TypeAlias.
|
||||
|
||||
Symbol::Kind kind() const;
|
||||
|
||||
std::string baseType() const;
|
||||
/// Returns the underlying base type.
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
||||
|
||||
|
||||
|
@ -168,6 +168,12 @@ void NameSpace::typeDefs(SymbolTable& table) const
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::typeAliases(SymbolTable& table) const
|
||||
{
|
||||
extract(Symbol::SYM_TYPEALIAS, table);
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::enums(SymbolTable& table) const
|
||||
{
|
||||
extract(Symbol::SYM_ENUM, table);
|
||||
|
@ -108,7 +108,12 @@ bool Parameter::vectorType(const std::string& type, NameSpace* pNS)
|
||||
if (pSym->kind() == Symbol::SYM_TYPEDEF)
|
||||
{
|
||||
TypeDef* pType = static_cast<TypeDef*>(pSym);
|
||||
ret = pType->declaration().find("vector") != std::string::npos;
|
||||
ret = pType->baseType().find("vector") != std::string::npos;
|
||||
}
|
||||
else if (pSym->kind() == Symbol::SYM_TYPEALIAS)
|
||||
{
|
||||
TypeAlias* pType = static_cast<TypeAlias*>(pSym);
|
||||
ret = pType->baseType().find("vector") != std::string::npos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ void Parser::parse()
|
||||
std::string m(exc.message());
|
||||
std::string where(_currentPath);
|
||||
where.append("(");
|
||||
where.append(NumberFormatter::format(static_cast<int>(_istr.getCurrentLineNumber())));
|
||||
where.append(NumberFormatter::format(_istr.getCurrentLineNumber()));
|
||||
where.append(")");
|
||||
throw SyntaxException(m, where);
|
||||
}
|
||||
@ -493,6 +493,8 @@ const Token* Parser::parseUsing(const Token* pNext)
|
||||
{
|
||||
poco_assert (isKeyword(pNext, IdentifierToken::KW_USING));
|
||||
|
||||
_pCurrentSymbol = 0;
|
||||
int line = _istr.getCurrentLineNumber();
|
||||
pNext = next();
|
||||
if (isKeyword(pNext, IdentifierToken::KW_NAMESPACE))
|
||||
{
|
||||
@ -511,13 +513,32 @@ const Token* Parser::parseUsing(const Token* pNext)
|
||||
{
|
||||
std::string id;
|
||||
pNext = parseIdentifier(pNext, id);
|
||||
currentNameSpace()->importSymbol(id);
|
||||
if (isOperator(pNext, OperatorToken::OP_ASSIGN))
|
||||
{
|
||||
pNext = next();
|
||||
std::string decl("using ");
|
||||
decl += id;
|
||||
decl += " = ";
|
||||
while (!isOperator(pNext, OperatorToken::OP_SEMICOLON) && !isEOF(pNext))
|
||||
{
|
||||
append(decl, pNext);
|
||||
pNext = next();
|
||||
}
|
||||
TypeAlias* pTypeAlias = new TypeAlias(decl, currentNameSpace());
|
||||
addSymbol(pTypeAlias, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentNameSpace()->importSymbol(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isOperator(pNext, OperatorToken::OP_SEMICOLON))
|
||||
syntaxError("semicolon");
|
||||
return next();
|
||||
pNext = next();
|
||||
_pCurrentSymbol = 0;
|
||||
return pNext;
|
||||
}
|
||||
|
||||
|
||||
|
@ -119,7 +119,7 @@ std::string Symbol::extractName(const std::string& decl)
|
||||
return "operator ()";
|
||||
else if (decl.find("operator[]") != std::string::npos)
|
||||
return "operator []";
|
||||
|
||||
|
||||
std::string::size_type pos = decl.find('(');
|
||||
// another special case: function pointer
|
||||
if (pos != std::string::npos && pos < decl.size() - 1)
|
||||
@ -137,7 +137,7 @@ std::string Symbol::extractName(const std::string& decl)
|
||||
}
|
||||
if (pos == std::string::npos || (pos > 0 && decl[pos - 1] == '('))
|
||||
pos = decl.size();
|
||||
--pos;
|
||||
if (pos > 0) --pos;
|
||||
// check for constant; start searching after template
|
||||
std::string::size_type eqStart = 0;
|
||||
if (decl.compare(0, 8, "template") == 0)
|
||||
@ -204,13 +204,16 @@ std::string Symbol::extractName(const std::string& decl)
|
||||
while (pos > 0 && isIdent(decl[pos - 1])) --pos;
|
||||
if (pos > 0 && decl[pos - 1] == '~') --pos;
|
||||
}
|
||||
|
||||
|
||||
while (pos > 2 && decl[pos - 1] == ':')
|
||||
{
|
||||
pos -= 3;
|
||||
while (pos > 0 && isIdent(decl[pos - 1])) --pos;
|
||||
}
|
||||
return decl.substr(pos, end - pos + 1);
|
||||
if (pos != std::string::npos)
|
||||
return decl.substr(pos, end - pos + 1);
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,4 +54,37 @@ std::string TypeDef::baseType() const
|
||||
}
|
||||
|
||||
|
||||
TypeAlias::TypeAlias(const std::string& decl, NameSpace* pNameSpace):
|
||||
Decl(decl, pNameSpace)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TypeAlias::~TypeAlias()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind TypeAlias::kind() const
|
||||
{
|
||||
return Symbol::SYM_TYPEALIAS;
|
||||
}
|
||||
|
||||
|
||||
std::string TypeAlias::baseType() const
|
||||
{
|
||||
std::string decl = declaration();
|
||||
if (decl.compare(0, 5, "using") == 0)
|
||||
{
|
||||
decl.erase(0, 5);
|
||||
std::string::size_type pos = 0;
|
||||
while (pos < decl.size() && std::isspace(decl[pos])) pos++;
|
||||
while (pos < decl.size() && decl[pos] != '=') pos++;
|
||||
decl.erase(0, pos);
|
||||
Poco::trimInPlace(decl);
|
||||
}
|
||||
return decl;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
||||
|
Loading…
x
Reference in New Issue
Block a user