mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-17 07:37:13 +02:00
Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
This commit is contained in:
154
vendor/POCO/CppParser/src/Attributes.cpp
vendored
Normal file
154
vendor/POCO/CppParser/src/Attributes.cpp
vendored
Normal file
@ -0,0 +1,154 @@
|
||||
//
|
||||
// Attributes.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: Attributes
|
||||
// Module: Attributes
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Attributes.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
using Poco::NumberParser;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
Attributes::Attributes()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Attributes::Attributes(const Attributes& attrs)
|
||||
{
|
||||
_map = attrs._map;
|
||||
}
|
||||
|
||||
|
||||
Attributes::~Attributes()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Attributes& Attributes::operator = (const Attributes& attrs)
|
||||
{
|
||||
AttrMap map(attrs._map);
|
||||
std::swap(_map, map);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool Attributes::has(const std::string& name) const
|
||||
{
|
||||
return _map.find(name) != _map.end();
|
||||
}
|
||||
|
||||
|
||||
std::string Attributes::getString(const std::string& name) const
|
||||
{
|
||||
AttrMap::const_iterator it = _map.find(name);
|
||||
if (it != _map.end())
|
||||
return it->second;
|
||||
else
|
||||
throw Poco::NotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
std::string Attributes::getString(const std::string& name, const std::string& defaultValue) const
|
||||
{
|
||||
AttrMap::const_iterator it = _map.find(name);
|
||||
if (it != _map.end())
|
||||
return it->second;
|
||||
else
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
int Attributes::getInt(const std::string& name) const
|
||||
{
|
||||
AttrMap::const_iterator it = _map.find(name);
|
||||
if (it != _map.end())
|
||||
return NumberParser::parse(it->second);
|
||||
else
|
||||
throw Poco::NotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
int Attributes::getInt(const std::string& name, int defaultValue) const
|
||||
{
|
||||
AttrMap::const_iterator it = _map.find(name);
|
||||
if (it != _map.end())
|
||||
return NumberParser::parse(it->second);
|
||||
else
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
bool Attributes::getBool(const std::string& name) const
|
||||
{
|
||||
AttrMap::const_iterator it = _map.find(name);
|
||||
if (it != _map.end())
|
||||
return it->second != "false";
|
||||
else
|
||||
throw Poco::NotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
bool Attributes::getBool(const std::string& name, bool defaultValue) const
|
||||
{
|
||||
AttrMap::const_iterator it = _map.find(name);
|
||||
if (it != _map.end())
|
||||
return it->second != "false";
|
||||
else
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
void Attributes::set(const std::string& name, const std::string& value)
|
||||
{
|
||||
_map[name] = value;
|
||||
}
|
||||
|
||||
|
||||
void Attributes::remove(const std::string& name)
|
||||
{
|
||||
AttrMap::iterator it = _map.find(name);
|
||||
if (it != _map.end())
|
||||
_map.erase(it);
|
||||
}
|
||||
|
||||
|
||||
const std::string& Attributes::operator [] (const std::string& name) const
|
||||
{
|
||||
AttrMap::const_iterator it = _map.find(name);
|
||||
if (it != _map.end())
|
||||
return it->second;
|
||||
else
|
||||
throw Poco::NotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
std::string& Attributes::operator [] (const std::string& name)
|
||||
{
|
||||
return _map[name];
|
||||
}
|
||||
|
||||
|
||||
void Attributes::clear()
|
||||
{
|
||||
_map.clear();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
147
vendor/POCO/CppParser/src/AttributesParser.cpp
vendored
Normal file
147
vendor/POCO/CppParser/src/AttributesParser.cpp
vendored
Normal file
@ -0,0 +1,147 @@
|
||||
//
|
||||
// AttributesParser.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: Attributes
|
||||
// Module: AttributesParser
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/AttributesParser.h"
|
||||
#include "Poco/CppParser/CppToken.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
using Poco::Token;
|
||||
using Poco::SyntaxException;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
AttributesParser::AttributesParser(Attributes& attrs, std::istream& istr):
|
||||
_attrs(attrs),
|
||||
_tokenizer(istr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AttributesParser::~AttributesParser()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AttributesParser::parse()
|
||||
{
|
||||
const Token* pNext = next();
|
||||
if (!isEOF(pNext))
|
||||
{
|
||||
pNext = parseAttributes(pNext);
|
||||
}
|
||||
if (!isEOF(pNext))
|
||||
throw Poco::SyntaxException("extra tokens found in attribute declaration");
|
||||
}
|
||||
|
||||
|
||||
const Token* AttributesParser::parseAttributes(const Token* pNext)
|
||||
{
|
||||
pNext = parseAttribute(pNext);
|
||||
while (isOperator(pNext, OperatorToken::OP_COMMA) || isIdentifier(pNext))
|
||||
{
|
||||
if (!isIdentifier(pNext)) pNext = next();
|
||||
pNext = parseAttribute(pNext);
|
||||
}
|
||||
return pNext;
|
||||
}
|
||||
|
||||
|
||||
const Token* AttributesParser::parseAttribute(const Token* pNext)
|
||||
{
|
||||
std::string id;
|
||||
std::string value;
|
||||
pNext = parseIdentifier(pNext, id);
|
||||
if (isOperator(pNext, OperatorToken::OP_ASSIGN))
|
||||
{
|
||||
pNext = next();
|
||||
if (isOperator(pNext, OperatorToken::OP_OPENBRACE))
|
||||
{
|
||||
pNext = parseComplexAttribute(pNext, id);
|
||||
}
|
||||
else if (isIdentifier(pNext) || isLiteral(pNext))
|
||||
{
|
||||
value = pNext->asString();
|
||||
pNext = next();
|
||||
}
|
||||
else throw SyntaxException("bad attribute declaration");
|
||||
}
|
||||
setAttribute(id, value);
|
||||
return pNext;
|
||||
}
|
||||
|
||||
|
||||
const Token* AttributesParser::parseComplexAttribute(const Token* pNext, const std::string& id)
|
||||
{
|
||||
poco_assert_dbg (isOperator(pNext, OperatorToken::OP_OPENBRACE));
|
||||
|
||||
pNext = next();
|
||||
std::string oldId(_id);
|
||||
if (!_id.empty())
|
||||
{
|
||||
_id.append(".");
|
||||
_id.append(id);
|
||||
}
|
||||
else _id = id;
|
||||
pNext = parseAttributes(pNext);
|
||||
_id = oldId;
|
||||
if (isOperator(pNext, OperatorToken::OP_CLOSBRACE))
|
||||
pNext = next();
|
||||
else
|
||||
throw SyntaxException("bad attribute declaration");
|
||||
|
||||
return pNext;
|
||||
}
|
||||
|
||||
|
||||
const Token* AttributesParser::parseIdentifier(const Token* pNext, std::string& id)
|
||||
{
|
||||
if (isIdentifier(pNext))
|
||||
{
|
||||
id = pNext->asString();
|
||||
pNext = next();
|
||||
while (isOperator(pNext, OperatorToken::OP_PERIOD))
|
||||
{
|
||||
id.append(".");
|
||||
pNext = next();
|
||||
if (isIdentifier(pNext))
|
||||
{
|
||||
id.append(pNext->asString());
|
||||
pNext = next();
|
||||
}
|
||||
else throw SyntaxException("identifier expected");
|
||||
}
|
||||
return pNext;
|
||||
}
|
||||
else throw SyntaxException("identifier expected");
|
||||
}
|
||||
|
||||
|
||||
void AttributesParser::setAttribute(const std::string& name, const std::string& value)
|
||||
{
|
||||
std::string n;
|
||||
if (!_id.empty())
|
||||
{
|
||||
n.append(_id);
|
||||
n.append(".");
|
||||
}
|
||||
n.append(name);
|
||||
_attrs.set(n, value);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
47
vendor/POCO/CppParser/src/BuiltIn.cpp
vendored
Normal file
47
vendor/POCO/CppParser/src/BuiltIn.cpp
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
//
|
||||
// BuiltIn.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: BuiltIn
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/BuiltIn.h"
|
||||
#include "Poco/String.h"
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
BuiltIn::BuiltIn(const std::string& name, NameSpace* pNameSpace):
|
||||
Symbol(name, pNameSpace)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BuiltIn::~BuiltIn()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind BuiltIn::kind() const
|
||||
{
|
||||
return Symbol::SYM_BUILTIN;
|
||||
}
|
||||
|
||||
|
||||
std::string BuiltIn::toString() const
|
||||
{
|
||||
return fullName();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
786
vendor/POCO/CppParser/src/CppToken.cpp
vendored
Normal file
786
vendor/POCO/CppParser/src/CppToken.cpp
vendored
Normal file
@ -0,0 +1,786 @@
|
||||
//
|
||||
// CppToken.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: CppParser
|
||||
// Module: CppToken
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/CppToken.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
using Poco::Token;
|
||||
using Poco::SyntaxException;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
CppToken::CppToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppToken::~CppToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CppToken::syntaxError(const std::string& expected, const std::string& actual)
|
||||
{
|
||||
std::string msg("expected: ");
|
||||
msg.append(expected);
|
||||
msg.append(", got: ");
|
||||
msg.append(actual);
|
||||
throw SyntaxException(msg);
|
||||
}
|
||||
|
||||
|
||||
OperatorToken::OperatorToken()
|
||||
{
|
||||
int i = 1;
|
||||
_opMap["["] = i++;
|
||||
_opMap["]"] = i++;
|
||||
_opMap["("] = i++;
|
||||
_opMap[")"] = i++;
|
||||
_opMap["{"] = i++;
|
||||
_opMap["}"] = i++;
|
||||
_opMap["<"] = i++;
|
||||
_opMap["<="] = i++;
|
||||
_opMap["<<"] = i++;
|
||||
_opMap["<<="] = i++;
|
||||
_opMap[">"] = i++;
|
||||
_opMap[">="] = i++;
|
||||
_opMap[">>"] = i++;
|
||||
_opMap[">>="] = i++;
|
||||
_opMap["="] = i++;
|
||||
_opMap["=="] = i++;
|
||||
_opMap["!"] = i++;
|
||||
_opMap["!="] = i++;
|
||||
_opMap["&"] = i++;
|
||||
_opMap["&="] = i++;
|
||||
_opMap["&&"] = i++;
|
||||
_opMap["|"] = i++;
|
||||
_opMap["|="] = i++;
|
||||
_opMap["||"] = i++;
|
||||
_opMap["^"] = i++;
|
||||
_opMap["^="] = i++;
|
||||
_opMap["~"] = i++;
|
||||
_opMap["*"] = i++;
|
||||
_opMap["*="] = i++;
|
||||
_opMap["/"] = i++;
|
||||
_opMap["/="] = i++;
|
||||
_opMap["+"] = i++;
|
||||
_opMap["+="] = i++;
|
||||
_opMap["++"] = i++;
|
||||
_opMap["-"] = i++;
|
||||
_opMap["-="] = i++;
|
||||
_opMap["--"] = i++;
|
||||
_opMap["->"] = i++;
|
||||
_opMap["%"] = i++;
|
||||
_opMap["%="] = i++;
|
||||
_opMap[","] = i++;
|
||||
_opMap["."] = i++;
|
||||
_opMap["..."] = i++;
|
||||
_opMap[":"] = i++;
|
||||
_opMap["::"] = i++;
|
||||
_opMap[";"] = i++;
|
||||
_opMap["?"] = i++;
|
||||
}
|
||||
|
||||
|
||||
OperatorToken::~OperatorToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Token::Class OperatorToken::tokenClass() const
|
||||
{
|
||||
return Token::OPERATOR_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
bool OperatorToken::start(char c, std::istream& istr)
|
||||
{
|
||||
_value = c;
|
||||
char next = (char) istr.peek();
|
||||
switch (_value[0])
|
||||
{
|
||||
case '[':
|
||||
case ']':
|
||||
case '(':
|
||||
case ')':
|
||||
case '{':
|
||||
case '}':
|
||||
case '<':
|
||||
case '>':
|
||||
case '=':
|
||||
case '!':
|
||||
case '&':
|
||||
case '|':
|
||||
case '*':
|
||||
case '+':
|
||||
case '-':
|
||||
case '^':
|
||||
case '~':
|
||||
case ',':
|
||||
case ':':
|
||||
case ';':
|
||||
case '%':
|
||||
case '?':
|
||||
return true;
|
||||
case '.':
|
||||
return !(next >= '0' && next <= '9');
|
||||
case '/':
|
||||
return !(next == '/' || next == '*');
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OperatorToken::finish(std::istream& istr)
|
||||
{
|
||||
int next = (char) istr.peek();
|
||||
switch (_value[0])
|
||||
{
|
||||
case '(':
|
||||
case ')':
|
||||
case '{':
|
||||
case '}':
|
||||
case '[':
|
||||
case ']':
|
||||
case ';':
|
||||
case '?':
|
||||
case '~':
|
||||
case ',':
|
||||
break;
|
||||
case '.':
|
||||
if (next == '.')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
if (istr.peek() != '.') syntaxError(".", std::string(1, (char) istr.peek()));
|
||||
_value += (char) istr.get();
|
||||
}
|
||||
break;
|
||||
case ':':
|
||||
if (next == ':') _value += (char) istr.get();
|
||||
break;
|
||||
case '<':
|
||||
if (next == '<')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = (char) istr.peek();
|
||||
}
|
||||
if (next == '=') _value += (char) istr.get();
|
||||
break;
|
||||
case '>':
|
||||
if (next == '>')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = (char) istr.peek();
|
||||
}
|
||||
if (next == '=') _value += (char) istr.get();
|
||||
break;
|
||||
case '&':
|
||||
if (next == '&' || next == '=') _value += (char) istr.get();
|
||||
break;
|
||||
case '|':
|
||||
if (next == '|' || next == '=') _value += (char) istr.get();
|
||||
break;
|
||||
case '+':
|
||||
if (next == '+' || next == '=') _value += (char) istr.get();
|
||||
break;
|
||||
case '-':
|
||||
if (next == '-' || next == '=' || next == '>') _value += (char) istr.get();
|
||||
break;
|
||||
case '=':
|
||||
case '!':
|
||||
case '*':
|
||||
case '/':
|
||||
case '^':
|
||||
case '%':
|
||||
if (next == '=') _value += (char) istr.get();
|
||||
break;
|
||||
default:
|
||||
poco_bugcheck();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int OperatorToken::asInteger() const
|
||||
{
|
||||
OpMap::const_iterator it = _opMap.find(_value);
|
||||
if (it != _opMap.end())
|
||||
return it->second;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
IdentifierToken::IdentifierToken()
|
||||
{
|
||||
int i = 1;
|
||||
_kwMap["alignas"] = i++;
|
||||
_kwMap["alignof"] = i++;
|
||||
_kwMap["and"] = i++;
|
||||
_kwMap["and_eq"] = i++;
|
||||
_kwMap["asm"] = i++;
|
||||
_kwMap["auto"] = i++;
|
||||
_kwMap["bitand"] = i++;
|
||||
_kwMap["bitor"] = i++;
|
||||
_kwMap["bool"] = i++;
|
||||
_kwMap["break"] = i++;
|
||||
_kwMap["case"] = i++;
|
||||
_kwMap["catch"] = i++;
|
||||
_kwMap["char"] = i++;
|
||||
_kwMap["char16_t"] = i++;
|
||||
_kwMap["char32_t"] = i++;
|
||||
_kwMap["class"] = i++;
|
||||
_kwMap["compl"] = i++;
|
||||
_kwMap["const"] = i++;
|
||||
_kwMap["constexpr"] = i++;
|
||||
_kwMap["const_cast"] = i++;
|
||||
_kwMap["continue"] = i++;
|
||||
_kwMap["decltype"] = i++;
|
||||
_kwMap["default"] = i++;
|
||||
_kwMap["delete"] = i++;
|
||||
_kwMap["do"] = i++;
|
||||
_kwMap["double"] = i++;
|
||||
_kwMap["dynamic_cast"] = i++;
|
||||
_kwMap["else"] = i++;
|
||||
_kwMap["enum"] = i++;
|
||||
_kwMap["explicit"] = i++;
|
||||
_kwMap["export"] = i++;
|
||||
_kwMap["extern"] = i++;
|
||||
_kwMap["false"] = i++;
|
||||
_kwMap["float"] = i++;
|
||||
_kwMap["for"] = i++;
|
||||
_kwMap["friend"] = i++;
|
||||
_kwMap["goto"] = i++;
|
||||
_kwMap["if"] = i++;
|
||||
_kwMap["inline"] = i++;
|
||||
_kwMap["int"] = i++;
|
||||
_kwMap["long"] = i++;
|
||||
_kwMap["mutable"] = i++;
|
||||
_kwMap["namespace"] = i++;
|
||||
_kwMap["new"] = i++;
|
||||
_kwMap["noexcept"] = i++;
|
||||
_kwMap["not"] = i++;
|
||||
_kwMap["not_eq"] = i++;
|
||||
_kwMap["nullptr"] = i++;
|
||||
_kwMap["operator"] = i++;
|
||||
_kwMap["or"] = i++;
|
||||
_kwMap["or_eq"] = i++;
|
||||
_kwMap["private"] = i++;
|
||||
_kwMap["protected"] = i++;
|
||||
_kwMap["public"] = i++;
|
||||
_kwMap["register"] = i++;
|
||||
_kwMap["reinterpret_cast"] = i++;
|
||||
_kwMap["return"] = i++;
|
||||
_kwMap["short"] = i++;
|
||||
_kwMap["signed"] = i++;
|
||||
_kwMap["sizeof"] = i++;
|
||||
_kwMap["static"] = i++;
|
||||
_kwMap["static_assert"] = i++;
|
||||
_kwMap["static_cast"] = i++;
|
||||
_kwMap["struct"] = i++;
|
||||
_kwMap["switch"] = i++;
|
||||
_kwMap["template"] = i++;
|
||||
_kwMap["this"] = i++;
|
||||
_kwMap["thread_local"] = i++;
|
||||
_kwMap["throw"] = i++;
|
||||
_kwMap["true"] = i++;
|
||||
_kwMap["try"] = i++;
|
||||
_kwMap["typedef"] = i++;
|
||||
_kwMap["typeid"] = i++;
|
||||
_kwMap["typename"] = i++;
|
||||
_kwMap["union"] = i++;
|
||||
_kwMap["unsigned"] = i++;
|
||||
_kwMap["using"] = i++;
|
||||
_kwMap["virtual"] = i++;
|
||||
_kwMap["void"] = i++;
|
||||
_kwMap["volatile"] = i++;
|
||||
_kwMap["wchar_t"] = i++;
|
||||
_kwMap["while"] = i++;
|
||||
_kwMap["xor"] = i++;
|
||||
_kwMap["xor_eq"] = i++;
|
||||
}
|
||||
|
||||
|
||||
IdentifierToken::~IdentifierToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Token::Class IdentifierToken::tokenClass() const
|
||||
{
|
||||
return asInteger() ? Token::KEYWORD_TOKEN : Token::IDENTIFIER_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
bool IdentifierToken::start(char c, std::istream& /*istr*/)
|
||||
{
|
||||
_value = c;
|
||||
return (c >= 'A' && c <= 'Z') ||
|
||||
(c >= 'a' && c <= 'z') ||
|
||||
(c == '_' || c == '$');
|
||||
}
|
||||
|
||||
|
||||
void IdentifierToken::finish(std::istream& istr)
|
||||
{
|
||||
int next = (char) istr.peek();
|
||||
while ((next >= 'A' && next <= 'Z') ||
|
||||
(next >= 'a' && next <= 'z') ||
|
||||
(next >= '0' && next <= '9') ||
|
||||
(next == '_' || next == '$'))
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int IdentifierToken::asInteger() const
|
||||
{
|
||||
KWMap::const_iterator it = _kwMap.find(_value);
|
||||
if (it != _kwMap.end())
|
||||
return it->second;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
StringLiteralToken::StringLiteralToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
StringLiteralToken::~StringLiteralToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Token::Class StringLiteralToken::tokenClass() const
|
||||
{
|
||||
return Token::STRING_LITERAL_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
bool StringLiteralToken::start(char c, std::istream& /*istr*/)
|
||||
{
|
||||
_value = c;
|
||||
return c == '"';
|
||||
}
|
||||
|
||||
|
||||
void StringLiteralToken::finish(std::istream& istr)
|
||||
{
|
||||
int next = istr.peek();
|
||||
while (next != -1 && next != '"' && next != '\n' && next != '\r')
|
||||
{
|
||||
if (next == '\\') _value += (char) istr.get();
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
if (next == '"')
|
||||
{
|
||||
next = istr.get();
|
||||
_value += (char) next;
|
||||
}
|
||||
else throw SyntaxException("Unterminated string literal");
|
||||
}
|
||||
|
||||
|
||||
std::string StringLiteralToken::asString() const
|
||||
{
|
||||
std::string result;
|
||||
std::string::const_iterator it = _value.begin();
|
||||
std::string::const_iterator end = _value.end();
|
||||
if (it != end)
|
||||
{
|
||||
if (*it == '"') ++it;
|
||||
while (it != end && *it != '"')
|
||||
{
|
||||
if (*it == '\\') ++it;
|
||||
if (it != end) result += *it++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
CharLiteralToken::CharLiteralToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CharLiteralToken::~CharLiteralToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Token::Class CharLiteralToken::tokenClass() const
|
||||
{
|
||||
return Token::CHAR_LITERAL_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
bool CharLiteralToken::start(char c, std::istream& /*istr*/)
|
||||
{
|
||||
_value = c;
|
||||
return c == '\'';
|
||||
}
|
||||
|
||||
|
||||
void CharLiteralToken::finish(std::istream& istr)
|
||||
{
|
||||
int next = istr.peek();
|
||||
while (next != -1 && next != '\'' && next != '\n' && next != '\r')
|
||||
{
|
||||
if (next == '\\') _value += (char) istr.get();
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
if (next == '\'')
|
||||
{
|
||||
next = istr.get();
|
||||
_value += (char) next;
|
||||
}
|
||||
else throw SyntaxException("Unterminated character literal");
|
||||
}
|
||||
|
||||
|
||||
char CharLiteralToken::asChar() const
|
||||
{
|
||||
char result('\0');
|
||||
std::string::const_iterator it = _value.begin();
|
||||
std::string::const_iterator end = _value.end();
|
||||
if (it != end)
|
||||
{
|
||||
if (*it == '\'') ++it;
|
||||
while (it != end && *it != '\'')
|
||||
{
|
||||
if (*it == '\\') ++it;
|
||||
if (it != end) result = *it++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
NumberLiteralToken::NumberLiteralToken():
|
||||
_isFloat(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NumberLiteralToken::~NumberLiteralToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Token::Class NumberLiteralToken::tokenClass() const
|
||||
{
|
||||
return _isFloat ? Token::FLOAT_LITERAL_TOKEN : Token::INTEGER_LITERAL_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
bool NumberLiteralToken::start(char c, std::istream& istr)
|
||||
{
|
||||
_value = c;
|
||||
int next = istr.peek();
|
||||
return (c >= '0' && c <= '9') ||
|
||||
(c == '.' && next >= '0' && next <= '9');
|
||||
}
|
||||
|
||||
|
||||
void NumberLiteralToken::finish(std::istream& istr)
|
||||
{
|
||||
int next = istr.peek();
|
||||
_isFloat = false;
|
||||
if (_value[0] != '.') // starts with digit
|
||||
{
|
||||
if (_value[0] == '0')
|
||||
{
|
||||
if (next == 'x' || next == 'X')
|
||||
{
|
||||
return finishHex(istr, next);
|
||||
}
|
||||
else if (next == 'b' || next == 'B')
|
||||
{
|
||||
return finishBin(istr, next);
|
||||
}
|
||||
}
|
||||
while ((next >= '0' && next <= '9') || next == '\'')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
if (next == '.')
|
||||
{
|
||||
next = istr.get();
|
||||
next = istr.peek();
|
||||
if (next != '.')
|
||||
{
|
||||
_isFloat = true;
|
||||
_value += '.';
|
||||
}
|
||||
else // double period
|
||||
{
|
||||
istr.unget();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_isFloat = true;
|
||||
_value += istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
while (next >= '0' && next <= '9')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
if (next == 'e' || next == 'E')
|
||||
{
|
||||
_isFloat = true;
|
||||
finishExp(istr, next);
|
||||
}
|
||||
finishSuffix(istr, next);
|
||||
}
|
||||
|
||||
|
||||
void NumberLiteralToken::finishHex(std::istream& istr, int next)
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
while (std::isxdigit(next) || next == '\'')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
if (next == '.')
|
||||
{
|
||||
_isFloat = true;
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
while (std::isxdigit(next) || next == '\'')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
}
|
||||
if (next == 'p' || next == 'P')
|
||||
{
|
||||
finishExp(istr, next);
|
||||
}
|
||||
finishSuffix(istr, next);
|
||||
}
|
||||
|
||||
|
||||
void NumberLiteralToken::finishBin(std::istream& istr, int next)
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
while (next == '0' || next == '1' || next == '\'')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
finishSuffix(istr, next);
|
||||
}
|
||||
|
||||
|
||||
void NumberLiteralToken::finishExp(std::istream& istr, int next)
|
||||
{
|
||||
_isFloat = true;
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
if (next == '+' || next == '-')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
if (next >= '0' && next <= '9')
|
||||
{
|
||||
while (next >= '0' && next <= '9')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string s(1, (char) next);
|
||||
syntaxError("digit", s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NumberLiteralToken::finishSuffix(std::istream& istr, int next)
|
||||
{
|
||||
if (_isFloat)
|
||||
{
|
||||
if (next == 'L' || next == 'l' || next == 'F' || next == 'f')
|
||||
_value += (char) istr.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
while (next == 'L' || next == 'l' || next == 'U' || next == 'u')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int NumberLiteralToken::asInteger() const
|
||||
{
|
||||
return static_cast<int>(std::strtol(_value.c_str(), 0, 0));
|
||||
}
|
||||
|
||||
|
||||
double NumberLiteralToken::asFloat() const
|
||||
{
|
||||
return std::strtod(_value.c_str(), 0);
|
||||
}
|
||||
|
||||
|
||||
CommentToken::CommentToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CommentToken::~CommentToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Token::Class CommentToken::tokenClass() const
|
||||
{
|
||||
return (_value.length() > 2 && _value[2] == '/') ? Token::SPECIAL_COMMENT_TOKEN : Token::COMMENT_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
bool CommentToken::start(char c, std::istream& istr)
|
||||
{
|
||||
_value = c;
|
||||
int next = istr.peek();
|
||||
return c == '/' && (next == '*' || next == '/');
|
||||
}
|
||||
|
||||
|
||||
void CommentToken::finish(std::istream& istr)
|
||||
{
|
||||
int next = istr.peek();
|
||||
if (next == '/')
|
||||
{
|
||||
while (next != -1 && next != '\r' && next != '\n')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
next = istr.peek();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_value += (char) istr.get(); // *
|
||||
next = istr.peek();
|
||||
while (next != -1)
|
||||
{
|
||||
next = istr.get();
|
||||
_value += (char) next;
|
||||
if (next == '*' && istr.peek() == '/')
|
||||
{
|
||||
_value += (char) istr.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string CommentToken::asString() const
|
||||
{
|
||||
if (_value.length() > 2 && _value[2] == '/')
|
||||
return _value.substr(3);
|
||||
else
|
||||
return _value.substr(2);
|
||||
}
|
||||
|
||||
|
||||
PreprocessorToken::PreprocessorToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PreprocessorToken::~PreprocessorToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Token::Class PreprocessorToken::tokenClass() const
|
||||
{
|
||||
return Token::PREPROCESSOR_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
bool PreprocessorToken::start(char c, std::istream& /*istr*/)
|
||||
{
|
||||
_value = c;
|
||||
return c == '#';
|
||||
}
|
||||
|
||||
|
||||
void PreprocessorToken::finish(std::istream& istr)
|
||||
{
|
||||
int pb = -1;
|
||||
int next = istr.peek();
|
||||
while (next != -1 && next != '\r' && next != '\n')
|
||||
{
|
||||
if (next == '\\')
|
||||
{
|
||||
istr.get();
|
||||
int p = istr.peek();
|
||||
if (p == '\r')
|
||||
{
|
||||
istr.get();
|
||||
if (istr.peek() == '\n')
|
||||
p = istr.get();
|
||||
next = p;
|
||||
}
|
||||
else if (p == '\n')
|
||||
{
|
||||
next = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
pb = next;
|
||||
}
|
||||
}
|
||||
if (next != -1)
|
||||
{
|
||||
_value += (char) (pb != -1 ? pb : istr.get());
|
||||
next = istr.peek();
|
||||
pb = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
||||
|
42
vendor/POCO/CppParser/src/Decl.cpp
vendored
Normal file
42
vendor/POCO/CppParser/src/Decl.cpp
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// Decl.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: Decl
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Decl.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
Decl::Decl(const std::string& decl, NameSpace* pNameSpace):
|
||||
Symbol(extractName(decl), pNameSpace),
|
||||
_decl(Poco::trim(decl))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Decl::~Decl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string Decl::toString() const
|
||||
{
|
||||
return _decl;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
||||
|
94
vendor/POCO/CppParser/src/Enum.cpp
vendored
Normal file
94
vendor/POCO/CppParser/src/Enum.cpp
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
//
|
||||
// Enum.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: Enum
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Enum.h"
|
||||
#include "Poco/CppParser/EnumValue.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::NumberFormatter;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
int Enum::_count = 0;
|
||||
|
||||
|
||||
Enum::Enum(const std::string& name, NameSpace* pNameSpace, int flags):
|
||||
Symbol(processName(name), pNameSpace),
|
||||
_flags(flags)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Enum::~Enum()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Enum::addValue(EnumValue* pValue)
|
||||
{
|
||||
poco_check_ptr (pValue);
|
||||
|
||||
_values.push_back(pValue);
|
||||
}
|
||||
|
||||
|
||||
Enum::Iterator Enum::begin() const
|
||||
{
|
||||
return _values.begin();
|
||||
}
|
||||
|
||||
|
||||
Enum::Iterator Enum::end() const
|
||||
{
|
||||
return _values.end();
|
||||
}
|
||||
|
||||
|
||||
std::string Enum::processName(const std::string& name)
|
||||
{
|
||||
if (name.empty())
|
||||
{
|
||||
std::string result("#AnonEnum");
|
||||
result.append(NumberFormatter::format0(_count++, 4));
|
||||
return result;
|
||||
}
|
||||
else return name;
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind Enum::kind() const
|
||||
{
|
||||
return Symbol::SYM_ENUM;
|
||||
}
|
||||
|
||||
|
||||
std::string Enum::toString() const
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << "enum " << name() << "\n{\n";
|
||||
for (Iterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
ostr << "\t" << (*it)->toString() << "\n";
|
||||
}
|
||||
ostr << "};";
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
54
vendor/POCO/CppParser/src/EnumValue.cpp
vendored
Normal file
54
vendor/POCO/CppParser/src/EnumValue.cpp
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// EnumValue.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: EnumValue
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/EnumValue.h"
|
||||
#include "Poco/CppParser/Enum.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
EnumValue::EnumValue(const std::string& name, const std::string& value, Enum* pEnum):
|
||||
Symbol(name, pEnum->nameSpace()),
|
||||
_value(value)
|
||||
{
|
||||
pEnum->addValue(this);
|
||||
}
|
||||
|
||||
|
||||
EnumValue::~EnumValue()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind EnumValue::kind() const
|
||||
{
|
||||
return Symbol::SYM_ENUM_VALUE;
|
||||
}
|
||||
|
||||
|
||||
std::string EnumValue::toString() const
|
||||
{
|
||||
std::string result(name());
|
||||
if (!_value.empty())
|
||||
{
|
||||
result.append(" = ");
|
||||
result.append(_value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
255
vendor/POCO/CppParser/src/Function.cpp
vendored
Normal file
255
vendor/POCO/CppParser/src/Function.cpp
vendored
Normal file
@ -0,0 +1,255 @@
|
||||
//
|
||||
// Function.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: Function
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Function.h"
|
||||
#include "Poco/CppParser/Parameter.h"
|
||||
#include "Poco/CppParser/NameSpace.h"
|
||||
#include "Poco/CppParser/Struct.h"
|
||||
#include "Poco/CppParser/Utility.h"
|
||||
#include "Poco/String.h"
|
||||
#include <sstream>
|
||||
#include <cctype>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
Function::Function(const std::string& decl, NameSpace* pNameSpace):
|
||||
Decl(decl, pNameSpace),
|
||||
_flags(0),
|
||||
_retParam()
|
||||
{
|
||||
if (hasAttr(decl, "static"))
|
||||
_flags |= FN_STATIC;
|
||||
if (hasAttr(decl, "virtual"))
|
||||
_flags |= FN_VIRTUAL;
|
||||
if (hasAttr(decl, "inline"))
|
||||
_flags |= FN_INLINE;
|
||||
if (hasAttr(decl, "template"))
|
||||
_flags |= FN_TEMPLATE;
|
||||
|
||||
if (isMethod() || isFunction())
|
||||
{
|
||||
// parse the decl
|
||||
std::size_t pos = decl.rfind(name());
|
||||
_retParam = decl.substr(0, pos-1);
|
||||
// eliminate static, virtual, inline, template
|
||||
_retParam = replace(_retParam, "static ", "");
|
||||
_retParam = replace(_retParam, "virtual ", "");
|
||||
_retParam = replace(_retParam, "inline ", "");
|
||||
if (_flags & FN_TEMPLATE)
|
||||
{
|
||||
std::size_t pos2 = _retParam.find(">");
|
||||
poco_assert (pos2 != std::string::npos);
|
||||
_retParam = _retParam.substr(pos2+1);
|
||||
}
|
||||
Poco::trimInPlace(_retParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Function::~Function()
|
||||
{
|
||||
for (Parameters::iterator it = _params.begin(); it != _params.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Function::addParameter(Parameter* pParam)
|
||||
{
|
||||
_params.push_back(pParam);
|
||||
}
|
||||
|
||||
|
||||
Function::Iterator Function::begin() const
|
||||
{
|
||||
return _params.begin();
|
||||
}
|
||||
|
||||
|
||||
Function::Iterator Function::end() const
|
||||
{
|
||||
return _params.end();
|
||||
}
|
||||
|
||||
|
||||
void Function::makeInline()
|
||||
{
|
||||
_flags |= FN_INLINE;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeConst()
|
||||
{
|
||||
_flags |= FN_CONST;
|
||||
}
|
||||
|
||||
|
||||
void Function::makePureVirtual()
|
||||
{
|
||||
_flags |= FN_PURE_VIRTUAL;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeFinal()
|
||||
{
|
||||
_flags |= FN_FINAL;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeOverride()
|
||||
{
|
||||
_flags |= FN_OVERRIDE;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeNoexcept()
|
||||
{
|
||||
_flags |= FN_NOEXCEPT;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeDefault()
|
||||
{
|
||||
_flags |= FN_DEFAULT;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeDelete()
|
||||
{
|
||||
_flags |= FN_DELETE;
|
||||
}
|
||||
|
||||
|
||||
bool Function::isConstructor() const
|
||||
{
|
||||
return name() == nameSpace()->name();
|
||||
}
|
||||
|
||||
|
||||
bool Function::isDestructor() const
|
||||
{
|
||||
return name()[0] == '~';
|
||||
}
|
||||
|
||||
|
||||
bool Function::isMethod() const
|
||||
{
|
||||
return !isConstructor() && !isDestructor() && nameSpace()->kind() == Symbol::SYM_STRUCT;
|
||||
}
|
||||
|
||||
|
||||
bool Function::isFunction() const
|
||||
{
|
||||
return nameSpace()->kind() == Symbol::SYM_NAMESPACE;
|
||||
}
|
||||
|
||||
|
||||
int Function::countParameters() const
|
||||
{
|
||||
return (int) _params.size();
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind Function::kind() const
|
||||
{
|
||||
return Symbol::SYM_FUNCTION;
|
||||
}
|
||||
|
||||
|
||||
std::string Function::signature() const
|
||||
{
|
||||
std::string signature(declaration());
|
||||
if (signature.compare(0, 8, "virtual ") == 0)
|
||||
signature.erase(0, 8);
|
||||
else if (signature.compare(0, 7, "static ") == 0)
|
||||
signature.erase(0, 8);
|
||||
if (signature.compare(0, 7, "inline ") == 0)
|
||||
signature.erase(0, 7);
|
||||
signature += "(";
|
||||
bool isFirst = true;
|
||||
for (Iterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
if (isFirst)
|
||||
isFirst = false;
|
||||
else
|
||||
signature += ", ";
|
||||
std::string arg = (*it)->declaration();
|
||||
std::string::size_type pos = arg.size() - 1;
|
||||
while (pos > 0 && !std::isspace(arg[pos])) --pos;
|
||||
while (pos > 0 && std::isspace(arg[pos])) --pos;
|
||||
signature.append(arg, 0, pos + 1);
|
||||
}
|
||||
signature += ")";
|
||||
if (_flags & FN_CONST)
|
||||
signature += " const";
|
||||
return signature;
|
||||
}
|
||||
|
||||
|
||||
bool Function::isVirtual() const
|
||||
{
|
||||
if (_flags & FN_VIRTUAL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (isDestructor())
|
||||
{
|
||||
Struct* pClass = dynamic_cast<Struct*>(nameSpace());
|
||||
return pClass && pClass->hasVirtualDestructor();
|
||||
}
|
||||
else return getOverridden() != 0;
|
||||
}
|
||||
|
||||
|
||||
Function* Function::getOverridden() const
|
||||
{
|
||||
if (isMethod() && !(_flags & FN_STATIC))
|
||||
{
|
||||
Struct* pClass = dynamic_cast<Struct*>(nameSpace());
|
||||
if (pClass)
|
||||
{
|
||||
for (Struct::BaseIterator it = pClass->baseBegin(); it != pClass->baseEnd(); ++it)
|
||||
{
|
||||
if (it->pClass)
|
||||
{
|
||||
Function* pOverridden = it->pClass->findFunction(signature());
|
||||
if (pOverridden && pOverridden->isVirtual())
|
||||
return pOverridden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
std::string Function::toString() const
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << Decl::toString() << "(\n";
|
||||
for (Iterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
ostr << "\t" << (*it)->toString() << "\n";
|
||||
}
|
||||
ostr << ");";
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
252
vendor/POCO/CppParser/src/NameSpace.cpp
vendored
Normal file
252
vendor/POCO/CppParser/src/NameSpace.cpp
vendored
Normal file
@ -0,0 +1,252 @@
|
||||
//
|
||||
// Namespace.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: Namespace
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/NameSpace.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sstream>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
using Poco::ExistsException;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
NameSpace::NameSpace()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NameSpace::NameSpace(const std::string& name, NameSpace* pNameSpace):
|
||||
Symbol(name, pNameSpace)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NameSpace::~NameSpace()
|
||||
{
|
||||
for (SymbolTable::iterator it = _symbols.begin(); it != _symbols.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::addSymbol(Symbol* pSymbol)
|
||||
{
|
||||
poco_check_ptr (pSymbol);
|
||||
|
||||
_symbols.insert(SymbolTable::value_type(pSymbol->name(), pSymbol));
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::importSymbol(const std::string& fullName)
|
||||
{
|
||||
std::string localName;
|
||||
std::string::size_type pos = fullName.find_last_of(':');
|
||||
if (pos != std::string::npos && pos < fullName.size() - 1)
|
||||
{
|
||||
localName.assign(fullName, pos + 1, fullName.size() - pos - 1);
|
||||
_importedSymbols[localName] = fullName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::importNameSpace(const std::string& nameSpace)
|
||||
{
|
||||
_importedNameSpaces.push_back(nameSpace);
|
||||
}
|
||||
|
||||
|
||||
NameSpace::Iterator NameSpace::begin() const
|
||||
{
|
||||
return _symbols.begin();
|
||||
}
|
||||
|
||||
|
||||
NameSpace::Iterator NameSpace::end() const
|
||||
{
|
||||
return _symbols.end();
|
||||
}
|
||||
|
||||
|
||||
Symbol* NameSpace::lookup(const std::string& name) const
|
||||
{
|
||||
std::set<const NameSpace*> alreadyVisited;
|
||||
return lookup(name, alreadyVisited);
|
||||
}
|
||||
|
||||
|
||||
Symbol* NameSpace::lookup(const std::string& name, std::set<const NameSpace*>& alreadyVisited) const
|
||||
{
|
||||
Symbol* pSymbol = 0;
|
||||
|
||||
if (name.empty())
|
||||
return pSymbol;
|
||||
|
||||
if (alreadyVisited.find(this) != alreadyVisited.end())
|
||||
return pSymbol;
|
||||
std::string head;
|
||||
std::string tail;
|
||||
splitName(name, head, tail);
|
||||
|
||||
alreadyVisited.insert(this);
|
||||
bool currentNSInserted = true;
|
||||
|
||||
|
||||
if (head.empty())
|
||||
{
|
||||
alreadyVisited.insert(this);
|
||||
return root()->lookup(tail, alreadyVisited);
|
||||
}
|
||||
SymbolTable::const_iterator it = _symbols.find(head);
|
||||
if (it != _symbols.end())
|
||||
{
|
||||
pSymbol = it->second;
|
||||
if (!tail.empty())
|
||||
{
|
||||
alreadyVisited.insert(this);
|
||||
NameSpace* pNS = dynamic_cast<NameSpace*>(pSymbol);
|
||||
if (pNS)
|
||||
pSymbol = static_cast<NameSpace*>(pSymbol)->lookup(tail, alreadyVisited);
|
||||
else
|
||||
pSymbol = 0;
|
||||
}
|
||||
}
|
||||
else if (tail.empty())
|
||||
{
|
||||
AliasMap::const_iterator itAlias = _importedSymbols.find(head);
|
||||
if (itAlias != _importedSymbols.end())
|
||||
pSymbol = lookup(itAlias->second, alreadyVisited);
|
||||
else
|
||||
{
|
||||
for (NameSpaceVec::const_iterator itns = _importedNameSpaces.begin(); !pSymbol && itns != _importedNameSpaces.end(); ++itns)
|
||||
{
|
||||
Symbol* pNS = lookup(*itns, alreadyVisited);
|
||||
if (pNS && pNS->kind() == Symbol::SYM_NAMESPACE)
|
||||
{
|
||||
pSymbol = static_cast<NameSpace*>(pNS)->lookup(name, alreadyVisited);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
NameSpace* pNS = nameSpace();
|
||||
if (!pSymbol && pNS && (alreadyVisited.find(pNS) == alreadyVisited.end()))
|
||||
{
|
||||
// if we have to go up, never push the NS!
|
||||
if (currentNSInserted)
|
||||
alreadyVisited.erase(this);
|
||||
pSymbol = nameSpace()->lookup(name, alreadyVisited);
|
||||
}
|
||||
return pSymbol;
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::nameSpaces(SymbolTable& table) const
|
||||
{
|
||||
extract(Symbol::SYM_NAMESPACE, table);
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::typeDefs(SymbolTable& table) const
|
||||
{
|
||||
extract(Symbol::SYM_TYPEDEF, table);
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::typeAliases(SymbolTable& table) const
|
||||
{
|
||||
extract(Symbol::SYM_TYPEALIAS, table);
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::enums(SymbolTable& table) const
|
||||
{
|
||||
extract(Symbol::SYM_ENUM, table);
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::classes(SymbolTable& table) const
|
||||
{
|
||||
extract(Symbol::SYM_STRUCT, table);
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::functions(SymbolTable& table) const
|
||||
{
|
||||
extract(Symbol::SYM_FUNCTION, table);
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::variables(SymbolTable& table) const
|
||||
{
|
||||
extract(Symbol::SYM_VARIABLE, table);
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind NameSpace::kind() const
|
||||
{
|
||||
return Symbol::SYM_NAMESPACE;
|
||||
}
|
||||
|
||||
|
||||
std::string NameSpace::toString() const
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << "namespace " << name() << "\n{\n";
|
||||
for (Iterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
ostr << it->second->fullName() << "\n";
|
||||
ostr << it->second->toString() << "\n";
|
||||
}
|
||||
ostr << "}\n";
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::splitName(const std::string& name, std::string& head, std::string& tail)
|
||||
{
|
||||
std::string::size_type pos = name.find(':');
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
head.assign(name, 0, pos);
|
||||
pos += 2;
|
||||
poco_assert (pos < name.length());
|
||||
tail.assign(name, pos, name.length() - pos);
|
||||
}
|
||||
else head = name;
|
||||
}
|
||||
|
||||
|
||||
NameSpace* NameSpace::root()
|
||||
{
|
||||
static NameSpace root;
|
||||
return &root;
|
||||
}
|
||||
|
||||
|
||||
void NameSpace::extract(Symbol::Kind kind, SymbolTable& table) const
|
||||
{
|
||||
for (SymbolTable::const_iterator it = _symbols.begin(); it != _symbols.end(); ++it)
|
||||
{
|
||||
if (it->second->kind() == kind)
|
||||
table.insert(*it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
150
vendor/POCO/CppParser/src/Parameter.cpp
vendored
Normal file
150
vendor/POCO/CppParser/src/Parameter.cpp
vendored
Normal file
@ -0,0 +1,150 @@
|
||||
//
|
||||
// Parameter.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: Parameter
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Parameter.h"
|
||||
#include "Poco/CppParser/NameSpace.h"
|
||||
#include "Poco/CppParser/TypeDef.h"
|
||||
#include "Poco/CppParser/Utility.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
int Parameter::_count(0);
|
||||
|
||||
|
||||
Parameter::Parameter(const std::string& decl, Function* /*pFunction*/):
|
||||
Decl(handleDecl(decl), 0), // handle init values
|
||||
_type(),
|
||||
_isRef(false),
|
||||
_isPointer(false),
|
||||
_isConst(false)
|
||||
{
|
||||
std::size_t pos = declaration().rfind(name());
|
||||
std::string tmp;
|
||||
if (pos == 0 && name().size() == declaration().size())
|
||||
tmp = declaration();
|
||||
else
|
||||
tmp = declaration().substr(0, pos);
|
||||
_type = Poco::trim(tmp);
|
||||
std::size_t rightCut = _type.size();
|
||||
while (rightCut > 0 && (_type[rightCut-1] == '&' || _type[rightCut-1] == '*' || _type[rightCut-1] == '\t' || _type[rightCut-1] == ' '))
|
||||
{
|
||||
if (_type[rightCut-1] == '&')
|
||||
_isRef = true;
|
||||
if (_type[rightCut-1] == '*')
|
||||
_isPointer = true;
|
||||
--rightCut;
|
||||
}
|
||||
_type = Poco::trim(_type.substr(0, rightCut));
|
||||
if (_type.find("const ") == 0)
|
||||
{
|
||||
_isConst = true;
|
||||
_type = _type.substr(6);
|
||||
}
|
||||
if (_type.find("const\t") == 0)
|
||||
{
|
||||
_type = _type.substr(6);
|
||||
_isConst = true;
|
||||
}
|
||||
|
||||
Poco::trimInPlace(_type);
|
||||
pos = decl.find("=");
|
||||
_hasDefaultValue = (pos != std::string::npos);
|
||||
if (_hasDefaultValue)
|
||||
{
|
||||
_defaultDecl = decl.substr(pos + 1);
|
||||
Poco::trimInPlace(_defaultDecl);
|
||||
std::size_t posStart = _defaultDecl.find("(");
|
||||
std::size_t posEnd = _defaultDecl.rfind(")");
|
||||
if (posStart != std::string::npos && posEnd != std::string::npos)
|
||||
{
|
||||
_defaultValue = _defaultDecl.substr(posStart + 1, posEnd-posStart - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
poco_assert (posStart == std::string::npos && posEnd == std::string::npos);
|
||||
_defaultValue = _defaultDecl;
|
||||
}
|
||||
Poco::trimInPlace(_defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Parameter::~Parameter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind Parameter::kind() const
|
||||
{
|
||||
return Symbol::SYM_PARAMETER;
|
||||
}
|
||||
|
||||
|
||||
bool Parameter::vectorType(const std::string& type, NameSpace* pNS)
|
||||
{
|
||||
bool ret = type.find("vector") != std::string::npos;
|
||||
if (!ret)
|
||||
{
|
||||
Symbol* pSym = pNS->lookup(type);
|
||||
if (pSym)
|
||||
{
|
||||
if (pSym->kind() == Symbol::SYM_TYPEDEF)
|
||||
{
|
||||
TypeDef* pType = static_cast<TypeDef*>(pSym);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
std::string Parameter::handleDecl(const std::string& decl)
|
||||
{
|
||||
std::size_t pos = decl.find('=');
|
||||
std::string result(decl.substr(0, pos));
|
||||
// now check if we have to add a paramName
|
||||
Poco::trimInPlace(result);
|
||||
std::size_t posSpace = result.rfind(' ');
|
||||
bool mustAdd = false;
|
||||
if (posSpace>0)
|
||||
{
|
||||
std::string tmp(result.substr(posSpace+1));
|
||||
mustAdd = (tmp.find('<') != -1 || tmp.find('>') != -1 || tmp.find('*') != -1 || tmp.find('&') != -1);
|
||||
}
|
||||
else
|
||||
mustAdd = true;
|
||||
if (mustAdd)
|
||||
{
|
||||
result.append(" ");
|
||||
result.append("param");
|
||||
result.append(Poco::NumberFormatter::format(++_count));
|
||||
//never add the default val it breaks the upper class parser
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
1017
vendor/POCO/CppParser/src/Parser.cpp
vendored
Normal file
1017
vendor/POCO/CppParser/src/Parser.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
255
vendor/POCO/CppParser/src/Struct.cpp
vendored
Normal file
255
vendor/POCO/CppParser/src/Struct.cpp
vendored
Normal file
@ -0,0 +1,255 @@
|
||||
//
|
||||
// Struct.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: Struct
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Struct.h"
|
||||
#include "Poco/CppParser/Function.h"
|
||||
#include "Poco/String.h"
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
Struct::Struct(const std::string& decl, bool isClass, NameSpace* pNameSpace):
|
||||
NameSpace(extractName(decl), pNameSpace),
|
||||
_decl(decl),
|
||||
_flags(0),
|
||||
_isClass(isClass)
|
||||
{
|
||||
std::size_t pos = decl.find("template");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
_flags |= FN_TEMPLATE;
|
||||
std::size_t templTypeStart = decl.find("<", pos);
|
||||
std::size_t templTypeEnd = decl.find(">", templTypeStart);
|
||||
if (templTypeStart != std::string::npos && templTypeEnd != std::string::npos)
|
||||
{
|
||||
std::string templParam = decl.substr(templTypeStart+1, templTypeEnd-templTypeStart-1);
|
||||
Poco::trimInPlace(templParam);
|
||||
if (templParam.empty())
|
||||
_flags |= FN_TEMPLATE_SPECIALIZATION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Struct::~Struct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Struct::addBase(const std::string& name, Symbol::Access access, bool isVirtual)
|
||||
{
|
||||
Base base;
|
||||
base.name = name;
|
||||
base.access = access;
|
||||
base.isVirtual = isVirtual;
|
||||
base.pClass = 0;
|
||||
_bases.push_back(base);
|
||||
}
|
||||
|
||||
|
||||
Struct::BaseIterator Struct::baseBegin() const
|
||||
{
|
||||
return _bases.begin();
|
||||
}
|
||||
|
||||
|
||||
Struct::BaseIterator Struct::baseEnd() const
|
||||
{
|
||||
return _bases.end();
|
||||
}
|
||||
|
||||
|
||||
void Struct::addDerived(Struct* pClass)
|
||||
{
|
||||
poco_check_ptr (pClass);
|
||||
|
||||
_derived.push_back(pClass);
|
||||
}
|
||||
|
||||
|
||||
void Struct::fixupBases()
|
||||
{
|
||||
for (BaseClasses::iterator it = _bases.begin(); it != _bases.end(); ++it)
|
||||
{
|
||||
it->pClass = dynamic_cast<Struct*>(lookup(it->name));
|
||||
if (it->pClass)
|
||||
it->pClass->addDerived(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Struct::DerivedIterator Struct::derivedBegin() const
|
||||
{
|
||||
return _derived.begin();
|
||||
}
|
||||
|
||||
|
||||
Struct::DerivedIterator Struct::derivedEnd() const
|
||||
{
|
||||
return _derived.end();
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
struct CPLT
|
||||
{
|
||||
bool operator() (const Function* pF1, const Function* pF2) const
|
||||
{
|
||||
int pc1 = pF1->countParameters();
|
||||
int pc2 = pF2->countParameters();
|
||||
return pc1 < pc2;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
void Struct::constructors(Functions& functions) const
|
||||
{
|
||||
for (NameSpace::Iterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
Function* pFunc = dynamic_cast<Function*>(it->second);
|
||||
if (pFunc && pFunc->isConstructor())
|
||||
functions.push_back(pFunc);
|
||||
}
|
||||
std::sort(functions.begin(), functions.end(), CPLT());
|
||||
}
|
||||
|
||||
|
||||
void Struct::bases(std::set<std::string>& bases) const
|
||||
{
|
||||
for (BaseIterator it = baseBegin(); it != baseEnd(); ++it)
|
||||
{
|
||||
if (it->pClass)
|
||||
{
|
||||
bases.insert(it->pClass->fullName());
|
||||
it->pClass->bases(bases);
|
||||
}
|
||||
else bases.insert(it->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Function* Struct::destructor() const
|
||||
{
|
||||
for (NameSpace::Iterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
Function* pFunc = dynamic_cast<Function*>(it->second);
|
||||
if (pFunc && pFunc->isDestructor())
|
||||
return pFunc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Struct::methods(Symbol::Access access, Functions& functions) const
|
||||
{
|
||||
for (NameSpace::Iterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
Function* pFunc = dynamic_cast<Function*>(it->second);
|
||||
if (pFunc && pFunc->getAccess() == access && pFunc->isMethod())
|
||||
functions.push_back(pFunc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Struct::inheritedMethods(FunctionSet& functions) const
|
||||
{
|
||||
for (BaseIterator it = baseBegin(); it != baseEnd(); ++it)
|
||||
{
|
||||
Struct* pBase = it->pClass;
|
||||
if (pBase)
|
||||
{
|
||||
for (NameSpace::Iterator itm = pBase->begin(); itm != pBase->end(); ++itm)
|
||||
{
|
||||
Function* pFunc = dynamic_cast<Function*>(itm->second);
|
||||
if (pFunc && pFunc->getAccess() != Symbol::ACC_PRIVATE && pFunc->isMethod())
|
||||
functions.insert(pFunc);
|
||||
}
|
||||
pBase->inheritedMethods(functions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Struct::derived(StructSet& derived) const
|
||||
{
|
||||
for (DerivedIterator it = derivedBegin(); it != derivedEnd(); ++it)
|
||||
{
|
||||
derived.insert(*it);
|
||||
(*it)->derived(derived);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind Struct::kind() const
|
||||
{
|
||||
return Symbol::SYM_STRUCT;
|
||||
}
|
||||
|
||||
|
||||
Function* Struct::findFunction(const std::string& signature) const
|
||||
{
|
||||
for (NameSpace::Iterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
Function* pFunc = dynamic_cast<Function*>(it->second);
|
||||
if (pFunc && pFunc->signature() == signature)
|
||||
return pFunc;
|
||||
}
|
||||
for (BaseIterator it = baseBegin(); it != baseEnd(); ++it)
|
||||
{
|
||||
if (it->pClass)
|
||||
{
|
||||
Function* pFunc = it->pClass->findFunction(signature);
|
||||
if (pFunc) return pFunc;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool Struct::hasVirtualDestructor() const
|
||||
{
|
||||
Function* pFunc = destructor();
|
||||
if (pFunc && (pFunc->flags() & Function::FN_VIRTUAL))
|
||||
return true;
|
||||
for (BaseIterator it = baseBegin(); it != baseEnd(); ++it)
|
||||
{
|
||||
if (it->pClass && it->pClass->hasVirtualDestructor())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::string Struct::toString() const
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << declaration() << "\n{\n";
|
||||
for (Iterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
ostr << it->second->fullName() << "\n";
|
||||
ostr << it->second->toString() << "\n";
|
||||
}
|
||||
ostr << "};\n";
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
247
vendor/POCO/CppParser/src/Symbol.cpp
vendored
Normal file
247
vendor/POCO/CppParser/src/Symbol.cpp
vendored
Normal file
@ -0,0 +1,247 @@
|
||||
//
|
||||
// Symbol.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: Symbol
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Symbol.h"
|
||||
#include "Poco/CppParser/NameSpace.h"
|
||||
#include "Poco/CppParser/Utility.h"
|
||||
#include "Poco/String.h"
|
||||
#include <cctype>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
int Symbol::_nextId = 0;
|
||||
|
||||
|
||||
Symbol::Symbol():
|
||||
_id(_nextId++),
|
||||
_pNameSpace(0),
|
||||
_access(ACC_PUBLIC),
|
||||
_line(-1)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Symbol::Symbol(const std::string& name, NameSpace* pNameSpace):
|
||||
_id(_nextId++),
|
||||
_name(name),
|
||||
_pNameSpace(pNameSpace),
|
||||
_access(ACC_PUBLIC),
|
||||
_line(-1)
|
||||
{
|
||||
if (_pNameSpace)
|
||||
_pNameSpace->addSymbol(this);
|
||||
}
|
||||
|
||||
|
||||
Symbol::~Symbol()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Symbol::setAccess(Access access)
|
||||
{
|
||||
_access = access;
|
||||
}
|
||||
|
||||
|
||||
void Symbol::setDocumentation(const std::string& text)
|
||||
{
|
||||
_documentation = text;
|
||||
}
|
||||
|
||||
|
||||
void Symbol::addDocumentation(const std::string& text)
|
||||
{
|
||||
if (!_documentation.empty())
|
||||
_documentation.append("\n");
|
||||
_documentation.append(text);
|
||||
}
|
||||
|
||||
|
||||
void Symbol::setFile(const std::string& path)
|
||||
{
|
||||
_file = path;
|
||||
}
|
||||
|
||||
|
||||
void Symbol::setLineNumber(int line)
|
||||
{
|
||||
_line = line;
|
||||
}
|
||||
|
||||
|
||||
void Symbol::setPackage(const std::string& package)
|
||||
{
|
||||
_package = package;
|
||||
}
|
||||
|
||||
|
||||
void Symbol::setLibrary(const std::string& library)
|
||||
{
|
||||
_library = library;
|
||||
}
|
||||
|
||||
|
||||
std::string Symbol::fullName() const
|
||||
{
|
||||
std::string fullName;
|
||||
if (_pNameSpace)
|
||||
{
|
||||
fullName = _pNameSpace->fullName();
|
||||
if (!fullName.empty()) fullName.append("::");
|
||||
}
|
||||
fullName.append(_name);
|
||||
return fullName;
|
||||
}
|
||||
|
||||
|
||||
std::string Symbol::extractName(const std::string& decl)
|
||||
{
|
||||
poco_assert (!decl.empty());
|
||||
|
||||
// special cases: operator () and operator []
|
||||
if (decl.find("operator ()") != std::string::npos)
|
||||
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)
|
||||
{
|
||||
std::string::size_type i = pos + 1;
|
||||
while (i < decl.size() && std::isspace(decl[i])) i++;
|
||||
if (i < decl.size() && decl[i] == '*')
|
||||
{
|
||||
i++;
|
||||
std::string name;
|
||||
while (i < decl.size() && std::isspace(decl[i])) i++;
|
||||
while (i < decl.size() && !std::isspace(decl[i]) && decl[i] != ')') name += decl[i++];
|
||||
return name;
|
||||
}
|
||||
}
|
||||
if (pos == std::string::npos || (pos > 0 && decl[pos - 1] == '('))
|
||||
pos = decl.size();
|
||||
if (pos > 0) --pos;
|
||||
// check for constant; start searching after template
|
||||
std::string::size_type eqStart = 0;
|
||||
if (decl.compare(0, 8, "template") == 0)
|
||||
{
|
||||
eqStart = 8;
|
||||
while (std::isspace(decl[eqStart]) && eqStart < decl.size()) ++eqStart;
|
||||
if (eqStart < decl.size() && decl[eqStart] == '<')
|
||||
{
|
||||
++eqStart;
|
||||
int tc = 1;
|
||||
while (tc > 0 && eqStart < decl.size())
|
||||
{
|
||||
if (decl[eqStart] == '<')
|
||||
++tc;
|
||||
else if (decl[eqStart] == '>')
|
||||
--tc;
|
||||
++eqStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string::size_type eqPos = decl.find('=', eqStart);
|
||||
if (eqPos != std::string::npos)
|
||||
{
|
||||
// special case: default template parameter
|
||||
std::string::size_type gtPos = decl.find('>', eqPos);
|
||||
std::string::size_type ltPos = decl.find('<', eqPos);
|
||||
if ((gtPos == std::string::npos || gtPos > pos || (ltPos != std::string::npos && gtPos > ltPos)) && eqPos < pos && eqPos > 0 && decl[eqPos + 1] != '=')
|
||||
pos = eqPos - 1;
|
||||
}
|
||||
while (pos > 0 && std::isspace(decl[pos])) --pos;
|
||||
while (pos > 0 && decl[pos] == ']')
|
||||
{
|
||||
--pos;
|
||||
while (pos > 0 && decl[pos] != '[') --pos;
|
||||
if (pos > 0) --pos;
|
||||
while (pos > 0 && std::isspace(decl[pos])) --pos;
|
||||
}
|
||||
// iterate over template (specialization)
|
||||
int nestedTemplateCount = 0;
|
||||
if (pos > 1 && decl[pos] == '>' && decl[pos-1] != '-' && decl[pos-1] != '>') // the operators ->, >>
|
||||
{
|
||||
--pos;
|
||||
++nestedTemplateCount;
|
||||
while (pos > 0 && nestedTemplateCount != 0)
|
||||
{
|
||||
if (decl[pos] == '<')
|
||||
--nestedTemplateCount;
|
||||
if (decl[pos] == '>')
|
||||
++nestedTemplateCount;
|
||||
--pos;
|
||||
}
|
||||
while (pos > 0 && std::isspace(decl[pos])) --pos;
|
||||
}
|
||||
std::string::size_type end = pos;
|
||||
std::string::size_type op = decl.find("operator ");
|
||||
if (op != std::string::npos && (op == 0 || std::isspace(decl[op - 1]) || decl[op - 1] == ':'))
|
||||
{
|
||||
pos = op;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (pos > 0 && !isIdent(decl[pos])) --pos;
|
||||
while (pos > 0 && std::isspace(decl[pos])) --pos;
|
||||
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;
|
||||
}
|
||||
if (pos != std::string::npos)
|
||||
return decl.substr(pos, end - pos + 1);
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
|
||||
bool Symbol::isIdent(char c)
|
||||
{
|
||||
return std::isalnum(c) || c == '_';
|
||||
}
|
||||
|
||||
|
||||
bool Symbol::hasAttr(const std::string& decl, const std::string& attr)
|
||||
{
|
||||
std::string attrS(attr);
|
||||
attrS += ' ';
|
||||
std::string::size_type pos = decl.find(attrS);
|
||||
return pos == 0 || (pos != std::string::npos && decl[pos - 1] == ' ');
|
||||
}
|
||||
|
||||
|
||||
void Symbol::setAttributes(const Attributes& attrs)
|
||||
{
|
||||
_attrs = attrs;
|
||||
}
|
||||
|
||||
|
||||
const Attributes& Symbol::getAttributes() const
|
||||
{
|
||||
return _attrs;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
46
vendor/POCO/CppParser/src/Tokenizer.cpp
vendored
Normal file
46
vendor/POCO/CppParser/src/Tokenizer.cpp
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Tokenizer.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: CppParser
|
||||
// Module: Tokenizer
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Tokenizer.h"
|
||||
#include "Poco/CppParser/CppToken.h"
|
||||
|
||||
|
||||
using Poco::StreamTokenizer;
|
||||
using Poco::WhitespaceToken;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
Tokenizer::Tokenizer(std::istream& istr):
|
||||
StreamTokenizer(istr)
|
||||
{
|
||||
addToken(new OperatorToken);
|
||||
addToken(new IdentifierToken);
|
||||
addToken(new StringLiteralToken);
|
||||
addToken(new CharLiteralToken);
|
||||
addToken(new NumberLiteralToken);
|
||||
addToken(new CommentToken, false);
|
||||
addToken(new PreprocessorToken);
|
||||
addToken(new WhitespaceToken);
|
||||
}
|
||||
|
||||
|
||||
Tokenizer::~Tokenizer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
91
vendor/POCO/CppParser/src/TypeDef.cpp
vendored
Normal file
91
vendor/POCO/CppParser/src/TypeDef.cpp
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
//
|
||||
// TypeDef.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: TypeDef
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/TypeDef.h"
|
||||
#include "Poco/String.h"
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
TypeDef::TypeDef(const std::string& decl, NameSpace* pNameSpace):
|
||||
Decl(decl, pNameSpace)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TypeDef::~TypeDef()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind TypeDef::kind() const
|
||||
{
|
||||
return Symbol::SYM_TYPEDEF;
|
||||
}
|
||||
|
||||
|
||||
std::string TypeDef::baseType() const
|
||||
{
|
||||
std::string decl = declaration();
|
||||
if (decl.compare(0, 7, "typedef") == 0)
|
||||
{
|
||||
decl.erase(0, 7);
|
||||
std::string::size_type pos = decl.size() - 1;
|
||||
while (pos > 0 && std::isspace(decl[pos])) pos--;
|
||||
while (pos > 0 && !std::isspace(decl[pos])) pos--;
|
||||
decl.resize(pos + 1);
|
||||
Poco::trimInPlace(decl);
|
||||
}
|
||||
return decl;
|
||||
}
|
||||
|
||||
|
||||
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++;
|
||||
if (pos < decl.size() && decl[pos] == '=') pos++;
|
||||
decl.erase(0, pos);
|
||||
Poco::trimInPlace(decl);
|
||||
}
|
||||
return decl;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
300
vendor/POCO/CppParser/src/Utility.cpp
vendored
Normal file
300
vendor/POCO/CppParser/src/Utility.cpp
vendored
Normal file
@ -0,0 +1,300 @@
|
||||
//
|
||||
// Utility.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: CppParser
|
||||
// Module: Utility
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Utility.h"
|
||||
#include "Poco/CppParser/Parser.h"
|
||||
#include "Poco/CppParser/Struct.h"
|
||||
#include "Poco/StringTokenizer.h"
|
||||
#include "Poco/Glob.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Process.h"
|
||||
#include "Poco/Environment.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <fstream>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
using Poco::StringTokenizer;
|
||||
using Poco::Glob;
|
||||
using Poco::Path;
|
||||
using Poco::File;
|
||||
using Poco::Process;
|
||||
using Poco::ProcessHandle;
|
||||
using Poco::Environment;
|
||||
using Poco::NumberFormatter;
|
||||
using Poco::Exception;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
void Utility::parseDir(const std::vector <std::string>& includePattern, const std::vector <std::string>& excludePattern, NameSpace::SymbolTable& st, const std::string& exec, const std::string& options, const std::string& path)
|
||||
{
|
||||
std::set<std::string> files;
|
||||
Utility::buildFileList(files, includePattern, excludePattern);
|
||||
for (std::set<std::string>::const_iterator it = files.begin(); it != files.end(); ++it)
|
||||
{
|
||||
Utility::parse(*it, st, exec, options, path);
|
||||
}
|
||||
Utility::fixup(st);
|
||||
}
|
||||
|
||||
|
||||
void Utility::parse(const std::string& file, NameSpace::SymbolTable& st, const std::string& exec, const std::string& options, const std::string& path)
|
||||
{
|
||||
std::string prepFile = Utility::preprocessFile(file, exec, options, path);
|
||||
Utility::parseOnly(file, st, prepFile, true);
|
||||
}
|
||||
|
||||
|
||||
void Utility::fixup(NameSpace::SymbolTable& st)
|
||||
{
|
||||
for (NameSpace::SymbolTable::iterator it = st.begin(); it != st.end(); ++it)
|
||||
{
|
||||
Struct* pStruct = dynamic_cast<Struct*>(it->second);
|
||||
if (pStruct)
|
||||
{
|
||||
pStruct->fixupBases();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Utility::detectPrefixAndIncludes(const std::string& origHFile, std::vector<std::string>& lines, std::string& prefix)
|
||||
{
|
||||
std::ifstream istr(origHFile.c_str());
|
||||
try
|
||||
{
|
||||
if (istr.good())
|
||||
{
|
||||
std::string x;
|
||||
istr >> x;
|
||||
while (x.find("#ifndef") == std::string::npos)
|
||||
istr >> x;
|
||||
StringTokenizer tokenizer(x, " \t", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
||||
poco_assert (tokenizer.count() == 2);
|
||||
StringTokenizer::Iterator itTmp = tokenizer.begin();
|
||||
++itTmp;
|
||||
std::string defValue = *itTmp;
|
||||
istr >> x;
|
||||
// now find the corresponding #define
|
||||
while (x.find(defValue) == std::string::npos)
|
||||
istr >> x;
|
||||
//now parse until a class def is found without a ; at the end
|
||||
bool stop = false;
|
||||
std::string prefixHint;
|
||||
do
|
||||
{
|
||||
istr >> x;
|
||||
// we add EVERYTHING to lines: reason: used macros/preprocessor defines, conditional includes should all be present in the generated code
|
||||
// just think about fwd declarations inside a NS_BEGIN ... NS_END block
|
||||
if (x.find("class") != std::string::npos && x.find(";") == std::string::npos)
|
||||
{
|
||||
StringTokenizer tok(x, " \t", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
||||
StringTokenizer::Iterator it = tok.begin();
|
||||
while (*it != "class" && it != tok.end())
|
||||
++it;
|
||||
// the next after class must be *_API or in case of a template it must be the class name
|
||||
++it;
|
||||
std::size_t apiPos = it->find("_API");
|
||||
if (apiPos != std::string::npos)
|
||||
{
|
||||
prefixHint = it->substr(0, apiPos);
|
||||
}
|
||||
stop = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
lines.push_back(x);
|
||||
}
|
||||
}
|
||||
while (!stop && !istr.eof());
|
||||
if (!stop)
|
||||
{
|
||||
lines.clear();
|
||||
prefix.clear();
|
||||
//throw Poco::SyntaxException("Failed to parse file " + origHFile + ".No class declared?");
|
||||
return;
|
||||
}
|
||||
|
||||
// now search the prefix
|
||||
if (lines.empty())
|
||||
{
|
||||
prefix.clear();
|
||||
return;
|
||||
}
|
||||
// the prefix for that file
|
||||
std::vector<std::string>::const_iterator it = lines.end();
|
||||
--it;
|
||||
std::vector<std::string>::const_iterator itBegin = lines.begin();
|
||||
for (; it != itBegin; --it)
|
||||
{
|
||||
std::size_t prefixPos = it->find("_BEGIN");
|
||||
if (prefixPos != std::string::npos)
|
||||
{
|
||||
prefix = it->substr(0, prefixPos);
|
||||
if (prefix != prefixHint && !prefixHint.empty())
|
||||
{
|
||||
throw Poco::SyntaxException("Conflicting prefixes detected: " + prefixHint + "<->" + prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else throw Poco::OpenFileException(origHFile);
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
istr.close();
|
||||
throw;
|
||||
}
|
||||
istr.close();
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::preprocessFile(const std::string& file, const std::string& exec, const std::string& options, const std::string& path)
|
||||
{
|
||||
Path pp(file);
|
||||
pp.setExtension("i");
|
||||
|
||||
std::string popts;
|
||||
for (std::string::const_iterator it = options.begin(); it != options.end(); ++it)
|
||||
{
|
||||
if (*it == '%')
|
||||
popts += pp.getBaseName();
|
||||
else
|
||||
popts += *it;
|
||||
}
|
||||
StringTokenizer tokenizer(popts, ",;\n", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
||||
std::vector<std::string> args(tokenizer.begin(), tokenizer.end());
|
||||
#ifdef _WIN32
|
||||
std::string quotedFile("\"");
|
||||
quotedFile += file;
|
||||
quotedFile += "\"";
|
||||
args.push_back(quotedFile);
|
||||
#else
|
||||
args.push_back(file);
|
||||
#endif
|
||||
if (!path.empty())
|
||||
{
|
||||
std::string newPath(Environment::get("PATH"));
|
||||
newPath += Path::pathSeparator();
|
||||
newPath += path;
|
||||
Environment::set("PATH", path);
|
||||
}
|
||||
|
||||
ProcessHandle proc = Process::launch(exec, args);
|
||||
int rc = Process::wait(proc);
|
||||
if (rc != 0)
|
||||
{
|
||||
throw Poco::RuntimeException("Failed to process file");
|
||||
}
|
||||
|
||||
return pp.getFileName();
|
||||
}
|
||||
|
||||
|
||||
void Utility::parseOnly(const std::string& file, NameSpace::SymbolTable& st, const std::string& preprocessedFile, bool removePreprocessedFile)
|
||||
{
|
||||
std::ifstream istr(preprocessedFile.c_str());
|
||||
try
|
||||
{
|
||||
if (istr.good())
|
||||
{
|
||||
Parser parser(st, file, istr);
|
||||
parser.parse();
|
||||
}
|
||||
else throw Poco::OpenFileException(preprocessedFile);
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
istr.close();
|
||||
if (removePreprocessedFile)
|
||||
removeFile(preprocessedFile);
|
||||
throw;
|
||||
}
|
||||
istr.close();
|
||||
if (removePreprocessedFile)
|
||||
removeFile(preprocessedFile);
|
||||
}
|
||||
|
||||
|
||||
void Utility::removeFile(const std::string& preprocessedfile)
|
||||
{
|
||||
try
|
||||
{
|
||||
File f(preprocessedfile);
|
||||
f.remove();
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Utility::buildFileList(std::set<std::string>& files, const std::vector<std::string>& includePattern, const std::vector<std::string>& excludePattern)
|
||||
{
|
||||
std::set<std::string> temp;
|
||||
std::vector <std::string>::const_iterator itInc = includePattern.begin();
|
||||
std::vector <std::string>::const_iterator itIncEnd = includePattern.end();
|
||||
|
||||
int options(0);
|
||||
#if defined(_WIN32)
|
||||
options |= Glob::GLOB_CASELESS;
|
||||
#endif
|
||||
|
||||
for (; itInc != itIncEnd; ++itInc)
|
||||
{
|
||||
Glob::glob(*itInc, temp, options);
|
||||
}
|
||||
|
||||
for (std::set<std::string>::const_iterator it = temp.begin(); it != temp.end(); ++it)
|
||||
{
|
||||
Path p(*it);
|
||||
bool include = true;
|
||||
std::vector <std::string>::const_iterator itExc = excludePattern.begin();
|
||||
std::vector <std::string>::const_iterator itExcEnd = excludePattern.end();
|
||||
for (; itExc != itExcEnd; ++itExc)
|
||||
{
|
||||
Glob glob(*itExc, options);
|
||||
if (glob.match(p.toString()))
|
||||
include = false;
|
||||
}
|
||||
if (include)
|
||||
files.insert(*it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string replace(const std::string& input, const std::string& oldToken, const std::string& newToken)
|
||||
{
|
||||
std::string result;
|
||||
std::size_t start = 0;
|
||||
std::size_t pos = 0;
|
||||
do
|
||||
{
|
||||
pos = input.find(oldToken, start);
|
||||
result.append(input.substr(start, pos-start));
|
||||
if (pos != std::string::npos)
|
||||
result.append(newToken);
|
||||
start = pos + oldToken.length();
|
||||
}
|
||||
while (pos != std::string::npos);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} } // namespace Poco::CppParser
|
76
vendor/POCO/CppParser/src/Variable.cpp
vendored
Normal file
76
vendor/POCO/CppParser/src/Variable.cpp
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
//
|
||||
// Variable.cpp
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: Variable
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CppParser/Variable.h"
|
||||
#include "Poco/String.h"
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace CppParser {
|
||||
|
||||
|
||||
Variable::Variable(const std::string& decl, NameSpace* pNameSpace):
|
||||
Decl(decl, pNameSpace),
|
||||
_flags(0),
|
||||
_isPointer(false),
|
||||
_type()
|
||||
{
|
||||
if (hasAttr(decl, "static"))
|
||||
_flags |= VAR_STATIC;
|
||||
if (hasAttr(decl, "mutable"))
|
||||
_flags |= VAR_MUTABLE;
|
||||
if (hasAttr(decl, "volatile"))
|
||||
_flags |= VAR_VOLATILE;
|
||||
if (hasAttr(decl, "const"))
|
||||
_flags |= VAR_CONST;
|
||||
|
||||
std::size_t pos = decl.rfind(name());
|
||||
std::string tmp = decl.substr(0, pos);
|
||||
tmp = Poco::trim(tmp);
|
||||
|
||||
pos = tmp.rfind("*");
|
||||
_isPointer = (pos == (tmp.size()-1));
|
||||
|
||||
Poco::replaceInPlace(tmp, "static ", "");
|
||||
Poco::replaceInPlace(tmp, "mutable ", "");
|
||||
Poco::replaceInPlace(tmp, "volatile ", "");
|
||||
Poco::replaceInPlace(tmp, "static\t", "");
|
||||
Poco::replaceInPlace(tmp, "mutable\t", "");
|
||||
Poco::replaceInPlace(tmp, "volatile\t", "");
|
||||
if (tmp.find("const ") == 0)
|
||||
tmp = tmp.substr(6);
|
||||
if (tmp.find("const\t") == 0)
|
||||
tmp = tmp.substr(6);
|
||||
|
||||
std::size_t rightCut = tmp.size();
|
||||
while (rightCut > 0 && (tmp[rightCut-1] == '&' || tmp[rightCut-1] == '*' || tmp[rightCut-1] == '\t' || tmp[rightCut-1] == ' '))
|
||||
--rightCut;
|
||||
_type = Poco::trim(tmp.substr(0, rightCut));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Variable::~Variable()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Symbol::Kind Variable::kind() const
|
||||
{
|
||||
return Symbol::SYM_VARIABLE;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::CppParser
|
Reference in New Issue
Block a user