mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-21 15:51:43 +02:00
updated CppParser
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Attributes.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Attributes.cpp#1 $
|
||||
// $Id: //poco/1.4/CppParser/src/Attributes.cpp#2 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: Attributes
|
||||
@@ -143,6 +143,14 @@ void Attributes::set(const std::string& name, const std::string& 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);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// AttributesParser.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/AttributesParser.cpp#1 $
|
||||
// $Id: //poco/1.4/CppParser/src/AttributesParser.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: Attributes
|
||||
|
69
CppParser/src/BuiltIn.cpp
Normal file
69
CppParser/src/BuiltIn.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// BuiltIn.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppParser/src/BuiltIn.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
// Module: BuiltIn
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#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
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// CppToken.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/CppToken.cpp#4 $
|
||||
// $Id: //poco/1.4/CppParser/src/CppToken.cpp#2 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: CppParser
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "Poco/CppParser/CppToken.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
|
||||
@@ -613,14 +614,14 @@ void NumberLiteralToken::finish(std::istream& istr)
|
||||
|
||||
int NumberLiteralToken::asInteger() const
|
||||
{
|
||||
return static_cast<int>(strtol(_value.c_str(), 0, 0));
|
||||
return static_cast<int>(std::strtol(_value.c_str(), 0, 0));
|
||||
|
||||
}
|
||||
|
||||
|
||||
double NumberLiteralToken::asFloat() const
|
||||
{
|
||||
return strtod(_value.c_str(), 0);
|
||||
return std::strtod(_value.c_str(), 0);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Decl.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Decl.cpp#2 $
|
||||
// $Id: //poco/1.4/CppParser/src/Decl.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Enum.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Enum.cpp#1 $
|
||||
// $Id: //poco/1.4/CppParser/src/Enum.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// EnumValue.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/EnumValue.cpp#1 $
|
||||
// $Id: //poco/1.4/CppParser/src/EnumValue.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Function.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Function.cpp#3 $
|
||||
// $Id: //poco/1.4/CppParser/src/Function.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Namespace.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/NameSpace.cpp#3 $
|
||||
// $Id: //poco/1.4/CppParser/src/NameSpace.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Parameter.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Parameter.cpp#3 $
|
||||
// $Id: //poco/1.4/CppParser/src/Parameter.cpp#2 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
@@ -51,16 +51,18 @@ int Parameter::_count(0);
|
||||
|
||||
|
||||
Parameter::Parameter(const std::string& decl, Function* pFunction):
|
||||
Decl(handleDecl (decl), 0), // handle init values
|
||||
Decl(handleDecl(decl), 0), // handle init values
|
||||
_type(),
|
||||
_isRef(false),
|
||||
_isPointer(false),
|
||||
_isConst(false)
|
||||
{
|
||||
|
||||
std::size_t pos = declaration().rfind(name());
|
||||
|
||||
std::string tmp = declaration().substr(0, pos);
|
||||
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] == ' '))
|
||||
@@ -83,7 +85,6 @@ Parameter::Parameter(const std::string& decl, Function* pFunction):
|
||||
_isConst = true;
|
||||
}
|
||||
|
||||
|
||||
Poco::trimInPlace(_type);
|
||||
pos = decl.find("=");
|
||||
_hasDefaultValue = (pos != std::string::npos);
|
||||
@@ -154,7 +155,6 @@ std::string Parameter::handleDecl(const std::string& decl)
|
||||
mustAdd = true;
|
||||
if (mustAdd)
|
||||
{
|
||||
|
||||
result.append(" ");
|
||||
result.append("param");
|
||||
result.append(Poco::NumberFormatter::format(++_count));
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Parser.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Parser.cpp#7 $
|
||||
// $Id: //poco/1.4/CppParser/src/Parser.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: CppParser
|
||||
@@ -682,13 +682,18 @@ const Token* Parser::parseParameters(const Token* pNext, Function* pFunc)
|
||||
{
|
||||
std::string decl;
|
||||
int depth = 0;
|
||||
while ((depth > 0 || (!isOperator(pNext, OperatorToken::OP_CLOSPARENT) && !isOperator(pNext, OperatorToken::OP_COMMA))) && !isEOF(pNext))
|
||||
int tdepth = 0;
|
||||
while ((depth > 0 || tdepth > 0 || (!isOperator(pNext, OperatorToken::OP_CLOSPARENT) && !isOperator(pNext, OperatorToken::OP_COMMA))) && !isEOF(pNext))
|
||||
{
|
||||
append(decl, pNext);
|
||||
if (isOperator(pNext, OperatorToken::OP_OPENPARENT))
|
||||
++depth;
|
||||
else if (isOperator(pNext, OperatorToken::OP_CLOSPARENT))
|
||||
--depth;
|
||||
else if (isOperator(pNext, OperatorToken::OP_LT))
|
||||
++tdepth;
|
||||
else if (isOperator(pNext, OperatorToken::OP_GT))
|
||||
--tdepth;
|
||||
pNext = next();
|
||||
}
|
||||
if (isOperator(pNext, OperatorToken::OP_COMMA))
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Struct.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Struct.cpp#2 $
|
||||
// $Id: //poco/1.4/CppParser/src/Struct.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Symbol.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Symbol.cpp#6 $
|
||||
// $Id: //poco/1.4/CppParser/src/Symbol.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
@@ -136,8 +136,14 @@ 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('(');
|
||||
// check for function pointer
|
||||
// another special case: function pointer
|
||||
if (pos != std::string::npos && pos < decl.size() - 1)
|
||||
{
|
||||
std::string::size_type i = pos + 1;
|
||||
@@ -154,11 +160,14 @@ std::string Symbol::extractName(const std::string& decl)
|
||||
if (pos == std::string::npos || (pos > 0 && decl[pos - 1] == '('))
|
||||
pos = decl.size();
|
||||
--pos;
|
||||
// check for constant
|
||||
std::string::size_type eqPos = decl.find('=');
|
||||
if (eqPos != std::string::npos)
|
||||
{
|
||||
// special case: default template parameter
|
||||
std::string::size_type gtPos = decl.find('>', eqPos);
|
||||
if ((gtPos == std::string::npos || gtPos > pos) && eqPos < pos && eqPos > 0 && decl[eqPos + 1] != '=')
|
||||
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;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Tokenizer.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Tokenizer.cpp#1 $
|
||||
// $Id: //poco/1.4/CppParser/src/Tokenizer.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: CppParser
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// TypeDef.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/TypeDef.cpp#3 $
|
||||
// $Id: //poco/1.4/CppParser/src/TypeDef.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Utility.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Utility.cpp#5 $
|
||||
// $Id: //poco/1.4/CppParser/src/Utility.cpp#2 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: CppParser
|
||||
@@ -186,6 +186,7 @@ void Utility::detectPrefixAndIncludes(const std::string& origHFile, std::vector<
|
||||
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);
|
||||
@@ -276,17 +277,16 @@ void Utility::buildFileList(std::set<std::string>& files, const std::vector<std:
|
||||
Glob::glob(*itInc, temp, options);
|
||||
}
|
||||
|
||||
std::vector <std::string>::const_iterator itExc = excludePattern.begin();
|
||||
std::vector <std::string>::const_iterator itExcEnd = excludePattern.end();
|
||||
|
||||
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.getFileName()))
|
||||
if (glob.match(p.toString()))
|
||||
include = false;
|
||||
}
|
||||
if (include)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Variable.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/src/Variable.cpp#3 $
|
||||
// $Id: //poco/1.4/CppParser/src/Variable.cpp#1 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
|
Reference in New Issue
Block a user