new trunk (base for 1.5)

windows build only
This commit is contained in:
Aleksandar Fabijanic
2012-04-23 01:14:34 +00:00
parent f9b60296f7
commit d75e68c027
3760 changed files with 1058456 additions and 0 deletions

238
CppParser/src/Symbol.cpp Normal file
View File

@@ -0,0 +1,238 @@
//
// Symbol.cpp
//
// $Id: //poco/1.3/CppParser/src/Symbol.cpp#6 $
//
// Library: CppParser
// Package: SymbolTable
// Module: Symbol
//
// 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/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());
std::string::size_type pos = decl.find('(');
// check for 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();
--pos;
std::string::size_type eqPos = decl.find('=');
if (eqPos != std::string::npos)
{
std::string::size_type gtPos = decl.find('>', eqPos);
if ((gtPos == std::string::npos || gtPos > pos) && 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;
}
return decl.substr(pos, end - pos + 1);
}
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