mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
merge CppParser C++11 and other improvements from appinf
This commit is contained in:
@@ -77,6 +77,9 @@ public:
|
|||||||
void typeDefs(SymbolTable& table) const;
|
void typeDefs(SymbolTable& table) const;
|
||||||
/// Fills the symbol table with all type definitions.
|
/// 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;
|
void enums(SymbolTable& table) const;
|
||||||
/// Fills the symbol table with all enums.
|
/// Fills the symbol table with all enums.
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public:
|
|||||||
SYM_PARAMETER, /// A function parameter
|
SYM_PARAMETER, /// A function parameter
|
||||||
SYM_STRUCT, /// A struct or class
|
SYM_STRUCT, /// A struct or class
|
||||||
SYM_TYPEDEF, /// A typedef
|
SYM_TYPEDEF, /// A typedef
|
||||||
|
SYM_TYPEALIAS, /// A type alias (using)
|
||||||
SYM_BUILTIN, /// A built-in type
|
SYM_BUILTIN, /// A built-in type
|
||||||
SYM_VARIABLE /// A (member) variable
|
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
|
} } // 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
|
void NameSpace::enums(SymbolTable& table) const
|
||||||
{
|
{
|
||||||
extract(Symbol::SYM_ENUM, table);
|
extract(Symbol::SYM_ENUM, table);
|
||||||
|
|||||||
@@ -108,7 +108,12 @@ bool Parameter::vectorType(const std::string& type, NameSpace* pNS)
|
|||||||
if (pSym->kind() == Symbol::SYM_TYPEDEF)
|
if (pSym->kind() == Symbol::SYM_TYPEDEF)
|
||||||
{
|
{
|
||||||
TypeDef* pType = static_cast<TypeDef*>(pSym);
|
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 m(exc.message());
|
||||||
std::string where(_currentPath);
|
std::string where(_currentPath);
|
||||||
where.append("(");
|
where.append("(");
|
||||||
where.append(NumberFormatter::format(static_cast<int>(_istr.getCurrentLineNumber())));
|
where.append(NumberFormatter::format(_istr.getCurrentLineNumber()));
|
||||||
where.append(")");
|
where.append(")");
|
||||||
throw SyntaxException(m, where);
|
throw SyntaxException(m, where);
|
||||||
}
|
}
|
||||||
@@ -493,6 +493,8 @@ const Token* Parser::parseUsing(const Token* pNext)
|
|||||||
{
|
{
|
||||||
poco_assert (isKeyword(pNext, IdentifierToken::KW_USING));
|
poco_assert (isKeyword(pNext, IdentifierToken::KW_USING));
|
||||||
|
|
||||||
|
_pCurrentSymbol = 0;
|
||||||
|
int line = _istr.getCurrentLineNumber();
|
||||||
pNext = next();
|
pNext = next();
|
||||||
if (isKeyword(pNext, IdentifierToken::KW_NAMESPACE))
|
if (isKeyword(pNext, IdentifierToken::KW_NAMESPACE))
|
||||||
{
|
{
|
||||||
@@ -511,13 +513,32 @@ const Token* Parser::parseUsing(const Token* pNext)
|
|||||||
{
|
{
|
||||||
std::string id;
|
std::string id;
|
||||||
pNext = parseIdentifier(pNext, id);
|
pNext = parseIdentifier(pNext, 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);
|
currentNameSpace()->importSymbol(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!isOperator(pNext, OperatorToken::OP_SEMICOLON))
|
if (!isOperator(pNext, OperatorToken::OP_SEMICOLON))
|
||||||
syntaxError("semicolon");
|
syntaxError("semicolon");
|
||||||
return next();
|
pNext = next();
|
||||||
|
_pCurrentSymbol = 0;
|
||||||
|
return pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ std::string Symbol::extractName(const std::string& decl)
|
|||||||
}
|
}
|
||||||
if (pos == std::string::npos || (pos > 0 && decl[pos - 1] == '('))
|
if (pos == std::string::npos || (pos > 0 && decl[pos - 1] == '('))
|
||||||
pos = decl.size();
|
pos = decl.size();
|
||||||
--pos;
|
if (pos > 0) --pos;
|
||||||
// check for constant; start searching after template
|
// check for constant; start searching after template
|
||||||
std::string::size_type eqStart = 0;
|
std::string::size_type eqStart = 0;
|
||||||
if (decl.compare(0, 8, "template") == 0)
|
if (decl.compare(0, 8, "template") == 0)
|
||||||
@@ -210,7 +210,10 @@ std::string Symbol::extractName(const std::string& decl)
|
|||||||
pos -= 3;
|
pos -= 3;
|
||||||
while (pos > 0 && isIdent(decl[pos - 1])) --pos;
|
while (pos > 0 && isIdent(decl[pos - 1])) --pos;
|
||||||
}
|
}
|
||||||
|
if (pos != std::string::npos)
|
||||||
return decl.substr(pos, end - pos + 1);
|
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
|
} } // namespace Poco::CppParser
|
||||||
|
|||||||
Reference in New Issue
Block a user