1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-25 19:47:12 +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:
Sandu Liviu Catalin
2021-01-30 08:51:39 +02:00
parent e0e34b4030
commit 4a6bfc086c
6219 changed files with 1209835 additions and 454916 deletions

View File

@ -0,0 +1,123 @@
//
// Attributes.h
//
// Library: CppParser
// Package: Attributes
// Module: Attributes
//
// Definition of the Attributes class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Attributes_INCLUDED
#define CppParser_Attributes_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include <map>
namespace Poco {
namespace CppParser {
class CppParser_API Attributes
/// This class stores attributes for a symbol table entry.
/// Attributes are simple name-value pairs, where both
/// name and values are strings.
{
public:
typedef std::map<std::string, std::string> AttrMap;
typedef AttrMap::const_iterator Iterator;
Attributes();
/// Creates the Attributes object.
Attributes(const Attributes& attrs);
/// Creates the Attributes object by copying another one.
~Attributes();
/// Destroys the Attributes object.
Attributes& operator = (const Attributes& attrs);
/// Assignment operator.
bool has(const std::string& name) const;
/// Returns true if an attribute with the given name exists.
std::string getString(const std::string& name) const;
/// Returns the attribute's value as a string.
///
/// Throws a Poco::NotFoundException if the attribute does not exist.
std::string getString(const std::string& name, const std::string& defaultValue) const;
/// Returns the attribute's value as a string, if it exists.
/// Returns the defaultValue if the attribute does not exist.
int getInt(const std::string& name) const;
/// Returns the attribute's value as an integer.
///
/// Throws a Poco::NotFoundException if the attribute does not exist.
/// Throws a Poco::SyntaxException if the stored value is not an integer.
int getInt(const std::string& name, int defaultValue) const;
/// Returns the attribute's value as an integer, if it exists.
/// Returns the defaultValue if the attribute does not exist.
///
/// Throws a Poco::SyntaxException if the stored value is not an integer.
bool getBool(const std::string& name) const;
/// Returns the attribute's value as a boolean.
/// The returned value is 'true', iff the stored value is not "false".
///
/// Throws a Poco::NotFoundException if the attribute does not exist.
bool getBool(const std::string& name, bool defaultValue) const;
/// Returns the attribute's value as a boolean, if it exists.
/// The returned value is 'true', iff the stored value is not "false".
void set(const std::string& name, const std::string& value);
/// Sets the value of an attribute.
void remove(const std::string& name);
/// Removes the attribute with the given name.
/// Does nothing if the attribute does not exist.
const std::string& operator [] (const std::string& name) const;
std::string& operator [] (const std::string& name);
Iterator begin() const;
Iterator end() const;
void clear();
/// Clears all attributes.
private:
AttrMap _map;
};
//
// inlines
//
inline Attributes::Iterator Attributes::begin() const
{
return _map.begin();
}
inline Attributes::Iterator Attributes::end() const
{
return _map.end();
}
} } // namespace Poco::CppParser
#endif // CppParser_Attributes_INCLUDED

View File

@ -0,0 +1,114 @@
//
// AttributesParser.h
//
// Library: CppParser
// Package: Attributes
// Module: AttributesParser
//
// Definition of the AttributesParser class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_AttributesParser_INCLUDED
#define CppParser_AttributesParser_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Tokenizer.h"
#include "Poco/CppParser/Attributes.h"
namespace Poco {
namespace CppParser {
class CppParser_API AttributesParser
/// A parser for POCO-style C++ attributes.
///
/// Using a special comment syntax, C++ declarations for
/// structs/classes, functions, types, etc. can be annotated
/// with attributes.
///
/// Attributes always come immediately before the symbol that
/// is being annotated, and are written inside special comments
/// with the syntax:
/// //@ <attrDecl>[,<attrDec>...]
/// where <attrDecl> is
/// <name>[=<value>]
/// <name> is a valid C++ identifier, or two identifiers separated by
/// a period (struct accessor notation).
/// <value> is a string, integer, identifier, bool literal, or a complex value
/// in the form
/// {<name>=<value>[,<name>=<value>...]}
{
public:
AttributesParser(Attributes& attrs, std::istream& istr);
/// Creates the AttributesParser.
~AttributesParser();
/// Destroys the AttributesParser.
void parse();
/// Parses attributes.
protected:
void setAttribute(const std::string& name, const std::string& value);
const Poco::Token* parseAttributes(const Poco::Token* pNext);
const Poco::Token* parseAttribute(const Poco::Token* pNext);
const Poco::Token* parseComplexAttribute(const Token* pNext, const std::string& id);
const Poco::Token* parseIdentifier(const Poco::Token* pNext, std::string& id);
const Poco::Token* next();
static bool isIdentifier(const Poco::Token* pToken);
static bool isOperator(const Poco::Token* pToken, int kind);
static bool isLiteral(const Poco::Token* pToken);
static bool isEOF(const Poco::Token* pToken);
private:
Attributes& _attrs;
Tokenizer _tokenizer;
std::string _id;
};
//
// inlines
//
inline const Poco::Token* AttributesParser::next()
{
return _tokenizer.next();
}
inline bool AttributesParser::isEOF(const Poco::Token* pToken)
{
return pToken->is(Token::EOF_TOKEN);
}
inline bool AttributesParser::isIdentifier(const Poco::Token* pToken)
{
return pToken->is(Poco::Token::IDENTIFIER_TOKEN) || pToken->is(Poco::Token::KEYWORD_TOKEN);
}
inline bool AttributesParser::isOperator(const Poco::Token* pToken, int kind)
{
return pToken->is(Poco::Token::OPERATOR_TOKEN) && pToken->asInteger() == kind;
}
inline bool AttributesParser::isLiteral(const Poco::Token* pToken)
{
return pToken->is(Poco::Token::STRING_LITERAL_TOKEN) || pToken->is(Poco::Token::INTEGER_LITERAL_TOKEN);
}
} } // namespace Poco::CppParser
#endif // CppParser_AttributesParser_INCLUDED

View File

@ -0,0 +1,47 @@
//
// BuiltIn.h
//
// Library: CppParser
// Package: SymbolTable
// Module: BuiltIn
//
// Definition of the BuiltIn class.
//
// Copyright (c) 2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_BuiltIn_INCLUDED
#define CppParser_BuiltIn_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Symbol.h"
namespace Poco {
namespace CppParser {
class CppParser_API BuiltIn: public Symbol
/// A placeholder for a built-in type.
{
public:
BuiltIn(const std::string& name, NameSpace* pNameSpace);
/// Creates the BuiltIn.
~BuiltIn();
/// Destroys the BuiltIn.
Symbol::Kind kind() const;
std::string toString() const;
};
} } // namespace Poco::CppParser
#endif // CppParser_BuiltIn_INCLUDED

View File

@ -0,0 +1,58 @@
//
// CppParser.h
//
// Library: CppParser
// Package: CppParser
// Module: CppParser
//
// Basic definitions for the Poco CppParser library.
// This file must be the first file included by every other CppParser
// header file.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_CppParser_INCLUDED
#define CppParser_CppParser_INCLUDED
#include "Poco/Foundation.h"
//
// The following block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the CppParser_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// CppParser_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if (defined(_WIN32) || defined(__CYGWIN__)) && defined(POCO_DLL)
#if defined(CppParser_EXPORTS)
#define CppParser_API __declspec(dllexport)
#else
#define CppParser_API __declspec(dllimport)
#endif
#endif
#if !defined(CppParser_API)
#define CppParser_API
#endif
//
// Automatically link CppParser library.
//
#if defined(_MSC_VER)
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(CppParser_EXPORTS)
#pragma comment(lib, "PocoCppParser" POCO_LIB_SUFFIX)
#endif
#endif
#endif // CppParser_CppParser_INCLUDED

View File

@ -0,0 +1,287 @@
//
// CppToken.h
//
// Library: CppParser
// Package: CppParser
// Module: CppToken
//
// Definition of the CppToken class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_CppToken_INCLUDED
#define CppParser_CppToken_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/Token.h"
#include <map>
namespace Poco {
namespace CppParser {
class CppParser_API CppToken: public Poco::Token
/// The base class for all C++ tokens.
{
public:
CppToken();
~CppToken();
protected:
void syntaxError(const std::string& expected, const std::string& actual);
};
class CppParser_API OperatorToken: public CppToken
{
public:
enum Tokens
{
OP_OPENBRACKET = 1, // [
OP_CLOSBRACKET, // ]
OP_OPENPARENT, // (
OP_CLOSPARENT, // )
OP_OPENBRACE, // {
OP_CLOSBRACE, // }
OP_LT, // <
OP_LE, // <=
OP_SHL, // <<
OP_SHL_ASSIGN, // <<=
OP_GT, // >
OP_GE, // >=
OP_SHR, // >>
OP_SHR_ASSIGN, // >>=
OP_ASSIGN, // =
OP_EQ, // ==
OP_NOT, // !
OP_NE, // !=
OP_BITAND, // &
OP_BITAND_ASSIGN, // &=
OP_AND, // &&
OP_BITOR, // |
OP_BITOR_ASSIGN, // |=
OP_OR, // ||
OP_XOR, // ^
OP_XOR_ASSIGN, // ^=
OP_COMPL, // ~
OP_ASTERISK, // *
OP_ASTERISK_ASSIGN, // *=
OP_SLASH, // /
OP_SLASH_ASSIGN, // /=
OP_PLUS, // +
OP_PLUS_ASSIGN, // +=
OP_INCR, // ++
OP_MINUS, // -
OP_MINUS_ASSIGN, // -=
OP_DECR, // --
OP_ARROW, // ->
OP_MOD, // %
OP_MOD_ASSIGN, // %=
OP_COMMA, // ,
OP_PERIOD, // .
OP_TRIPLE_PERIOD, // ...
OP_COLON, // :
OP_DBL_COLON, // ::
OP_SEMICOLON, // ;
OP_QUESTION // ?
};
OperatorToken();
~OperatorToken();
Poco::Token::Class tokenClass() const;
bool start(char c, std::istream& istr);
void finish(std::istream& istr);
int asInteger() const;
private:
typedef std::map<std::string, int> OpMap;
OpMap _opMap;
};
class CppParser_API IdentifierToken: public CppToken
{
public:
enum Keywords
{
KW_ALIGNAS = 1,
KW_ALIGNOF,
KW_AND,
KW_AND_EQ,
KW_ASM,
KW_AUTO,
KW_BITAND,
KW_BITOR,
KW_BOOL,
KW_BREAK,
KW_CASE,
KW_CATCH,
KW_CHAR,
KW_CHAR_16T,
KW_CHAR_32T,
KW_CLASS,
KW_COMPL,
KW_CONST,
KW_CONSTEXPR,
KW_CONST_CAST,
KW_CONTINUE,
KW_DECLTYPE,
KW_DEFAULT,
KW_DELETE,
KW_DO,
KW_DOUBLE,
KW_DYNAMIC_CAST,
KW_ELSE,
KW_ENUM,
KW_EXPLICIT,
KW_EXPORT,
KW_EXTERN,
KW_FALSE,
KW_FLOAT,
KW_FOR,
KW_FRIEND,
KW_GOTO,
KW_IF,
KW_INLINE,
KW_INT,
KW_LONG,
KW_MUTABLE,
KW_NAMESPACE,
KW_NEW,
KW_NOEXCEPT,
KW_NOT,
KW_NOT_EQ,
KW_NULLPTR,
KW_OPERATOR,
KW_OR,
KW_OR_EQ,
KW_PRIVATE,
KW_PROTECTED,
KW_PUBLIC,
KW_REGISTER,
KW_REINTERPRET_CAST,
KW_RETURN,
KW_SHORT,
KW_SIGNED,
KW_SIZEOF,
KW_STATIC,
KW_STATIC_ASSERT,
KW_STATIC_CAST,
KW_STRUCT,
KW_SWITCH,
KW_TEMPLATE,
KW_THIS,
KW_THREAD_LOCAL,
KW_THROW,
KW_TRUE,
KW_TRY,
KW_TYPEDEF,
KW_TYPEID,
KW_TYPENAME,
KW_UNION,
KW_UNSIGNED,
KW_USING,
KW_VIRTUAL,
KW_VOID,
KW_VOLATILE,
KW_WCHAR_T,
KW_WHILE,
KW_XOR,
KW_XOR_EQ
};
IdentifierToken();
~IdentifierToken();
Poco::Token::Class tokenClass() const;
bool start(char c, std::istream& istr);
void finish(std::istream& istr);
int asInteger() const;
private:
typedef std::map<std::string, int> KWMap;
KWMap _kwMap;
};
class CppParser_API StringLiteralToken: public CppToken
{
public:
StringLiteralToken();
~StringLiteralToken();
Poco::Token::Class tokenClass() const;
bool start(char c, std::istream& istr);
void finish(std::istream& istr);
std::string asString() const;
};
class CppParser_API CharLiteralToken: public CppToken
{
public:
CharLiteralToken();
~CharLiteralToken();
Poco::Token::Class tokenClass() const;
bool start(char c, std::istream& istr);
void finish(std::istream& istr);
char asChar() const;
};
class CppParser_API NumberLiteralToken: public CppToken
{
public:
NumberLiteralToken();
~NumberLiteralToken();
Poco::Token::Class tokenClass() const;
bool start(char c, std::istream& istr);
void finish(std::istream& istr);
int asInteger() const;
double asFloat() const;
protected:
void finishHex(std::istream& istr, int next);
void finishBin(std::istream& istr, int next);
void finishExp(std::istream& istr, int next);
void finishSuffix(std::istream& istr, int next);
private:
bool _isFloat;
};
class CppParser_API CommentToken: public CppToken
{
public:
CommentToken();
~CommentToken();
Poco::Token::Class tokenClass() const;
bool start(char c, std::istream& istr);
void finish(std::istream& istr);
std::string asString() const;
};
class CppParser_API PreprocessorToken: public CppToken
{
public:
PreprocessorToken();
~PreprocessorToken();
Poco::Token::Class tokenClass() const;
bool start(char c, std::istream& istr);
void finish(std::istream& istr);
};
} } // namespace Poco::CppParser
#endif // CppParser_CppToken_INCLUDED

View File

@ -0,0 +1,62 @@
//
// Decl.h
//
// Library: CppParser
// Package: SymbolTable
// Module: Decl
//
// Definition of the Decl class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Decl_INCLUDED
#define CppParser_Decl_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Symbol.h"
namespace Poco {
namespace CppParser {
class CppParser_API Decl: public Symbol
/// This class represents a simple declaration in a C++ source file.
/// It is a base class for Function, TypeDef or Variable.
{
public:
Decl(const std::string& decl, NameSpace* pNameSpace);
/// Creates the Decl.
~Decl();
/// Destroys the Decl.
const std::string& declaration() const;
/// Returns the declaration.
std::string toString() const;
protected:
std::string _decl;
};
//
// inlines
//
inline const std::string& Decl::declaration() const
{
return _decl;
}
} } // namespace Poco::CppParser
#endif // CppParser_Decl_INCLUDED

View File

@ -0,0 +1,94 @@
//
// Enum.h
//
// Library: CppParser
// Package: SymbolTable
// Module: Enum
//
// Definition of the Enum class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Enum_INCLUDED
#define CppParser_Enum_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Symbol.h"
#include <vector>
namespace Poco {
namespace CppParser {
class EnumValue;
class CppParser_API Enum: public Symbol
/// This class represents an enum declaration.
///
/// An enumeration has an optional name and
/// a collection of EnumValues.
{
public:
typedef std::vector<EnumValue*> Values;
typedef Values::const_iterator Iterator;
enum Flags
{
ENUM_IS_CLASS = 0x01 // C++11 enum class
};
Enum(const std::string& name, NameSpace* pNameSpace, int flags = 0);
/// Creates the Enum.
///
/// If name is the empty string, an internal name
/// in the form #AnonEnum<n> (where <n> is a unique integer)
/// will be assigned.
~Enum();
/// Destroys the Enum.
void addValue(EnumValue* pValue);
/// Adds an enum value. The Enum takes ownership of the value.
Iterator begin() const;
/// Returns an iterator for iterating over the Enum's EnumValue's.
Iterator end() const;
/// Returns an iterator for iterating over the Enum's EnumValue's.
int flags() const;
Symbol::Kind kind() const;
std::string toString() const;
protected:
static std::string processName(const std::string& name);
private:
Values _values;
int _flags;
static int _count;
};
//
// inlines
//
inline int Enum::flags() const
{
return _flags;
}
} } // namespace Poco::CppParser
#endif // CppParser_Enum_INCLUDED

View File

@ -0,0 +1,66 @@
//
// EnumValue.h
//
// Library: CppParser
// Package: SymbolTable
// Module: EnumValue
//
// Definition of the EnumValue class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_EnumValue_INCLUDED
#define CppParser_EnumValue_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Symbol.h"
namespace Poco {
namespace CppParser {
class Enum;
class CppParser_API EnumValue: public Symbol
/// This class represents an enumeration value
/// inside an enum declaration.
{
public:
EnumValue(const std::string& name, const std::string& value, Enum* pEnum);
/// Creates the EnumValue, using the name and a value, which may be empty.
virtual ~EnumValue();
/// Destroys the EnumValue.
const std::string& value() const;
/// Returns the value, which may be empty.
Symbol::Kind kind() const;
std::string toString() const;
private:
std::string _value;
};
//
// inlines
//
inline const std::string& EnumValue::value() const
{
return _value;
}
} } // namespace Poco::CppParser
#endif // CppParser_EnumValue_INCLUDED

View File

@ -0,0 +1,166 @@
//
// Function.h
//
// Library: CppParser
// Package: SymbolTable
// Module: Function
//
// Definition of the Function class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Function_INCLUDED
#define CppParser_Function_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Decl.h"
#include <vector>
namespace Poco {
namespace CppParser {
class Parameter;
class CppParser_API Function: public Decl
/// This class represents a (member) function declaration.
{
public:
enum Flags
{
FN_STATIC = 1, /// The function is static.
FN_VIRTUAL = 2, /// The function is virtual.
FN_INLINE = 4, /// The function is inline.
FN_CONST = 8, /// The function is const.
FN_TEMPLATE = 16, /// The function is a template.
FN_PURE_VIRTUAL = 32, /// The function is pure virtual.
FN_FINAL = 64, /// The function is final.
FN_OVERRIDE = 128, /// The function is override.
FN_NOEXCEPT = 256, /// The function is noexcept.
FN_DEFAULT = 512, /// The function is default.
FN_DELETE = 1024 /// The function has been deleted.
};
typedef std::vector<Parameter*> Parameters;
typedef Parameters::const_iterator Iterator;
Function(const std::string& decl, NameSpace* pNameSpace);
/// Creates the Function.
~Function();
/// Destroys the Function.
void addParameter(Parameter* pParam);
/// Adds a parameter to the function.
const std::string& getReturnParameter() const;
Iterator begin() const;
/// Returns an iterator for iterating over the Function's Parameter's.
Iterator end() const;
/// Returns an iterator for iterating over the Function's Parameter's.
void makeInline();
/// Sets the FN_INLINE flag.
void makeConst();
/// Sets the FN_CONST flag.
void makePureVirtual();
/// Sets the FN_PURE_VIRTUAL flag.
void makeFinal();
/// Sets the FN_FINAL flag.
void makeOverride();
/// Sets the FN_OVERRIDE flag.
void makeNoexcept();
/// Sets the FN_NOEXCEPT flag.
void makeDefault();
/// Sets the FN_DEFAULT flag.
void makeDelete();
/// Sets the FN_DELETE flag.
int flags() const;
/// Returns the function's flags.
bool isConstructor() const;
/// Returns true iff the function is a constructor.
bool isDestructor() const;
/// Returns true iff the function is a destructor.
bool isMethod() const;
/// Returns true iff the function is a method (it's part of
/// a Struct and it's neither a constructor nor a destructor).
bool isFunction() const;
/// Returns true iff the function is not a member of a class
/// (a freestanding function).
bool isConst() const;
/// Returns true iff the method is const.
int countParameters() const;
/// Returns the number of parameters.
std::string signature() const;
/// Returns the signature of the function.
bool isVirtual() const;
/// Returns true if the method is virtual. Also examines base
/// classes to check for a virtual function with the same
/// signature.
Function* getOverridden() const;
/// If the function is virtual and overrides a function in a
/// base class, the base class function is returned.
/// Otherwise, null is returned.
Symbol::Kind kind() const;
std::string toString() const;
private:
Parameters _params;
int _flags;
std::string _retParam;
};
//
// inlines
//
inline int Function::flags() const
{
return _flags;
}
inline const std::string& Function::getReturnParameter() const
{
return _retParam;
}
inline bool Function::isConst() const
{
return (flags() & FN_CONST) != 0;
}
} } // namespace Poco::CppParser
#endif // CppParser_Function_INCLUDED

View File

@ -0,0 +1,141 @@
//
// NameSpace.h
//
// Library: CppParser
// Package: SymbolTable
// Module: NameSpace
//
// Definition of the NameSpace class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_NameSpace_INCLUDED
#define CppParser_NameSpace_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Symbol.h"
#include <map>
#include <vector>
#include <set>
namespace Poco {
namespace CppParser {
class CppParser_API NameSpace: public Symbol
/// This class represents a namespace.
{
public:
typedef std::multimap<std::string, Symbol*> SymbolTable;
typedef SymbolTable::const_iterator Iterator;
typedef std::map<std::string, std::string> AliasMap;
typedef std::vector<std::string> NameSpaceVec;
NameSpace();
/// Creates the NameSpace.
NameSpace(const std::string& name, NameSpace* pNameSpace = 0);
/// Creates the NameSpace.
~NameSpace();
/// Destroys the NameSpace.
void addSymbol(Symbol* pSymbol);
/// Adds a symbol to the namespace.
void importSymbol(const std::string& fullName);
/// Imports a symbol from another namespace (using <symbol>).
void importNameSpace(const std::string& nameSpace);
/// Imports a namespace (using namespace <namespace>).
Iterator begin() const;
/// Returns an iterator for iterating over the NameSpace's Symbol's.
Iterator end() const;
/// Returns an iterator for iterating over the NameSpace's Symbol's.
Symbol* lookup(const std::string& name) const;
/// Looks up the given name in the symbol table
/// and returns the corresponding symbol, or null
/// if no symbol can be found. The name can include
/// a namespace.
static NameSpace* root();
/// Returns the root namespace. Never delete this one!
void nameSpaces(SymbolTable& table) const;
/// Fills the symbol table with all namespaces.
void typeDefs(SymbolTable& table) const;
/// Fills the symbol table with all type definitions.
void typeAliases(SymbolTable& table) const;
/// Fills the symbol table with all type alias (using) definitions.
void enums(SymbolTable& table) const;
/// Fills the symbol table with all enums.
void classes(SymbolTable& table) const;
/// Fills the symbol table with all classes and structs.
void functions(SymbolTable& table) const;
/// Fills the symbol table with all functions.
void variables(SymbolTable& table) const;
/// Fills the symbol table with all variables.
const AliasMap& importedSymbols() const;
/// Returns a const reference to a SymbolTable containing all
/// imported symbols.
const NameSpaceVec& importedNameSpaces() const;
/// Returns a vector containing all imported namespaces.
Symbol::Kind kind() const;
std::string toString() const;
private:
Symbol* lookup(const std::string& name, std::set<const NameSpace*>& alreadyVisited) const;
/// Looks up the given name in the symbol table
/// and returns the corresponding symbol, or null
/// if no symbol can be found. The name can include
/// a namespace.
protected:
void extract(Symbol::Kind kind, SymbolTable& table) const;
static void splitName(const std::string& name, std::string& head, std::string& tail);
private:
SymbolTable _symbols;
AliasMap _importedSymbols;
NameSpaceVec _importedNameSpaces;
};
//
// inlines
//
inline const NameSpace::AliasMap& NameSpace::importedSymbols() const
{
return _importedSymbols;
}
inline const NameSpace::NameSpaceVec& NameSpace::importedNameSpaces() const
{
return _importedNameSpaces;
}
} } // namespace Poco::CppParser
#endif // CppParser_NameSpace_INCLUDED

View File

@ -0,0 +1,142 @@
//
// Parameter.h
//
// Library: CppParser
// Package: SymbolTable
// Module: Parameter
//
// Definition of the Parameter class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Parameter_INCLUDED
#define CppParser_Parameter_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Decl.h"
namespace Poco {
namespace CppParser {
class Function;
class CppParser_API Parameter: public Decl
/// This class represents a parameter to a function.
{
public:
Parameter(const std::string& decl, Function* pFunction);
/// Creates the Parameter.
~Parameter();
/// Destroys the Parameter.
Symbol::Kind kind() const;
bool isReference() const;
/// Returns true iff the parameter is a reference.
bool isPointer() const;
/// Returns true iff the parameter is a pointer.
bool isConst() const;
/// Returns true iff the parameter is const.
bool hasDefaultValue() const;
/// Returns true if a defaultvalue was set at this parameter,
/// Example: const std::string& data = std::string("default").
const std::string& declType() const;
/// Returns the type of the parameter without const and & if present.
///
/// Example: a type const std::string& -> std::string, a type const std::string* returns std::string
const std::string& defaultValue() const;
/// If hasDefaultValue() returns true, this method returns the default value, i.e. all data found between
/// the opening and closing bracket of the init string.
///
/// Example: for const std::string& data = std::string("default") it will return "default",
/// for = std::string() it will return a zero length string, for = ComplexClass(13,12, "test", 0);
/// it will return 13,12, "test", 0.
const std::string& defaultDecl() const;
/// If hasDefaultValue() returns true, this method returns the
/// default value declaration.
///
/// Example: for const std::string& data = std::string("default") it will return std::string("default").
static bool vectorType(const std::string& type, NameSpace* pNS);
private:
std::string handleDecl(const std::string& decl);
/// Removes initialization values, adds param Names if they are missing
private:
std::string _type;
bool _isRef;
bool _isPointer;
bool _isConst;
bool _hasDefaultValue;
std::string _defaultValue;
std::string _defaultDecl;
static int _count;
};
//
// inlines
//
inline const std::string& Parameter::declType() const
{
return _type;
}
inline bool Parameter::isReference() const
{
return _isRef;
}
inline bool Parameter::isConst() const
{
return _isConst;
}
inline bool Parameter::isPointer() const
{
return _isPointer;
}
inline bool Parameter::hasDefaultValue() const
{
return _hasDefaultValue;
}
inline const std::string& Parameter::defaultValue() const
{
return _defaultValue;
}
inline const std::string& Parameter::defaultDecl() const
{
return _defaultDecl;
}
} } // namespace Poco::CppParser
#endif // CppParser_Parameter_INCLUDED

View File

@ -0,0 +1,127 @@
//
// Parser.h
//
// Library: CppParser
// Package: CppParser
// Module: Parser
//
// Definition of the Parser class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Parser_INCLUDED
#define CppParser_Parser_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Tokenizer.h"
#include "Poco/CppParser/Symbol.h"
#include "Poco/CppParser/NameSpace.h"
#include "Poco/CountingStream.h"
#include <vector>
namespace Poco {
namespace CppParser {
class Enum;
class Struct;
class Function;
class CppParser_API Parser
/// A minimal parser for C++ (header files).
///
/// The parser reads a (preprocessed) source or header file and
/// builds a symbol table containing as much information as
/// the parser is able to extract from the file.
///
/// A special comment syntax is used for inline API documentation.
///
/// A comment starting with three consecutive slashes (///) contains
/// API documentation for a symbol (class, function, typedef, enum, etc.).
/// API documentation comments always come after the declaration, with the
/// exception of structs and classes, where the comments are expected
/// immediately before the opening brace.
{
public:
Parser(NameSpace::SymbolTable& gst, const std::string& file, std::istream& istr);
/// Creates the Parser.
~Parser();
/// Destroys the Parser.
void parse();
/// Parses the file.
protected:
const Poco::Token* parseFile(const Poco::Token* pNext);
const Poco::Token* parseNameSpace(const Poco::Token* pNext);
const Poco::Token* parseClass(const Poco::Token* pNext);
const Poco::Token* parseClass(const Poco::Token* pNext, std::string& decl);
const Poco::Token* parseTemplate(const Poco::Token* pNext);
const Poco::Token* parseTemplateArgs(const Poco::Token* pNext, std::string& decl);
const Poco::Token* parseVarFunc(const Poco::Token* pNext);
const Poco::Token* parseVarFunc(const Poco::Token* pNext, std::string& decl);
const Poco::Token* parseFriend(const Poco::Token* pNext);
const Poco::Token* parseExtern(const Poco::Token* pNext);
const Poco::Token* parseTypeDef(const Poco::Token* pNext);
const Poco::Token* parseUsing(const Poco::Token* pNext);
const Poco::Token* parseFunc(const Poco::Token* pNext, std::string& decl);
const Poco::Token* parseParameters(const Poco::Token* pNext, Function* pFunc);
const Poco::Token* parseBlock(const Poco::Token* pNext);
const Poco::Token* parseEnum(const Poco::Token* pNext);
const Poco::Token* parseEnumValue(const Poco::Token* pNext, Enum* pEnum);
const Poco::Token* parseBaseClassList(const Poco::Token* pNext, Struct* pClass);
const Poco::Token* parseClassMembers(const Poco::Token* pNext, Struct* pClass);
const Poco::Token* parseAccess(const Poco::Token* pNext);
const Poco::Token* parseIdentifier(const Poco::Token* pNext, std::string& id);
void addSymbol(Symbol* pSymbol, int lineNumber, bool addGST = true);
void pushNameSpace(NameSpace* pNameSpace, int lineNumber, bool addGST = true);
void popNameSpace();
NameSpace* currentNameSpace() const;
static bool isIdentifier(const Poco::Token* pToken);
static bool isOperator(const Poco::Token* pToken, int kind);
static bool isKeyword(const Poco::Token* pToken, int kind);
static bool isEOF(const Poco::Token* pToken);
static void expectOperator(const Poco::Token* pToken, int kind, const std::string& msg);
static void syntaxError(const std::string& msg);
static void append(std::string& decl, const std::string& token);
static void append(std::string& decl, const Poco::Token* pToken);
const Poco::Token* next();
const Poco::Token* nextPreprocessed();
const Poco::Token* nextToken();
private:
typedef std::vector<NameSpace*> NSStack;
NameSpace::SymbolTable& _gst;
Poco::CountingInputStream _istr;
Tokenizer _tokenizer;
std::string _file;
std::string _path;
std::string _currentPath;
bool _inFile;
std::string _package;
std::string _library;
NSStack _nsStack;
Symbol* _pCurrentSymbol;
Symbol::Access _access;
std::string _doc;
std::string _attrs;
};
} } // namespace Poco::CppParser
#endif // CppParser_Parser_INCLUDED

View File

@ -0,0 +1,205 @@
//
// Struct.h
//
// Library: CppParser
// Package: SymbolTable
// Module: Struct
//
// Definition of the Struct class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Struct_INCLUDED
#define CppParser_Struct_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/NameSpace.h"
#include <vector>
#include <set>
namespace Poco {
namespace CppParser {
class Function;
class CppParser_API Struct: public NameSpace
/// This class represents a struct or class declaration.
{
public:
enum Flags
{
FN_TEMPLATE = 1,
FN_INLINE = 2, // when the whole class is inlined in a c++ file
FN_TEMPLATE_SPECIALIZATION = 4,
FN_FINAL = 8
};
struct Base
{
Symbol::Access access;
bool isVirtual;
std::string name;
Struct* pClass;
};
typedef std::vector<Base> BaseClasses;
typedef BaseClasses::const_iterator BaseIterator;
typedef std::vector<Struct*> StructVec;
typedef StructVec::const_iterator DerivedIterator;
typedef std::vector<Function*> Functions;
typedef std::set<Function*> FunctionSet;
typedef std::set<Struct*> StructSet;
Struct(const std::string& decl, bool isClass, NameSpace* pNameSpace);
/// Creates the Struct.
~Struct();
/// Destroys the Struct.
void addBase(const std::string&, Symbol::Access access, bool isVirtual);
/// Adds a base class.
BaseIterator baseBegin() const;
/// Returns an iterator for iterating over all base classes.
BaseIterator baseEnd() const;
/// Returns an iterator for iterating over all base classes.
void fixupBases();
/// Adds pointers for all base classes.
void addDerived(Struct* pClass);
/// Adds a derived class.
DerivedIterator derivedBegin() const;
/// Returns an iterator for iterating over all derived classes.
DerivedIterator derivedEnd() const;
/// Returns an iterator for iterating over all derived classes.
const std::string& declaration() const;
/// Returns the declaration.
int flags() const;
/// Returns the struct's flags.
void makeInline();
/// Changes the class to a inline class, i.e. definition and implementation are hidden in a cpp file.
void makeFinal();
/// Makes the class final.
bool isInline() const;
/// Returns true if the complete class is inlined in a cpp file.
bool isFinal() const;
/// Returns true if the class is final.
void constructors(Functions& functions) const;
/// Returns all constructors, sorted by their parameter count.
Function* destructor() const;
/// Returns the destructor, or NULL if no
/// destructor is defined.
void methods(Symbol::Access access, Functions& functions) const;
/// Returns all functions with the given access.
void inheritedMethods(FunctionSet& functions) const;
/// Returns all inherited methods.
void bases(std::set<std::string>& bases) const;
/// Returns all base classes.
void derived(StructSet& derived) const;
/// Returns all derived classes.
Function* findFunction(const std::string& signature) const;
/// Finds a function with the given signature.
bool hasVirtualDestructor() const;
/// Returns true if the class CppParser_API or one if its base classes
/// has a virtual destructor.
bool isClass() const;
/// Returns true iff the struct was declared as class.
bool isDerived() const;
/// Returns true iff the struct or class is derived from another struct or class.
Symbol::Kind kind() const;
std::string toString() const;
private:
std::string _decl;
BaseClasses _bases;
StructVec _derived;
int _flags;
bool _isClass;
};
//
// inlines
//
inline const std::string& Struct::declaration() const
{
return _decl;
}
inline int Struct::flags() const
{
return _flags;
}
inline bool Struct::isClass() const
{
return _isClass;
}
inline void Struct::makeInline()
{
_flags |= FN_INLINE;
}
inline void Struct::makeFinal()
{
_flags |= FN_FINAL;
}
inline bool Struct::isInline() const
{
return (_flags & FN_INLINE) != 0;
}
inline bool Struct::isFinal() const
{
return (_flags & FN_FINAL) != 0;
}
inline bool Struct::isDerived() const
{
return !_bases.empty();
}
} } // namespace Poco::CppParser
#endif // CppParser_Struct_INCLUDED

View File

@ -0,0 +1,267 @@
//
// Symbol.h
//
// Library: CppParser
// Package: SymbolTable
// Module: Symbol
//
// Definition of the Symbol class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Symbol_INCLUDED
#define CppParser_Symbol_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Attributes.h"
#include "Poco/Foundation.h"
namespace Poco {
namespace CppParser {
class NameSpace;
class CppParser_API Symbol
/// This is the base class for all symbols in the symbol table.
///
/// Every symbol has a unique ID (int) and a namespace (which
/// may be null).
{
public:
enum Kind
{
SYM_ENUM, /// An enumeration
SYM_ENUM_VALUE, /// An enumeration value
SYM_FUNCTION, /// A (member) function
SYM_NAMESPACE, /// A namespace
SYM_PARAMETER, /// A function parameter
SYM_STRUCT, /// A struct or class
SYM_TYPEDEF, /// A typedef
SYM_TYPEALIAS, /// A type alias (using)
SYM_BUILTIN, /// A built-in type
SYM_VARIABLE /// A (member) variable
};
enum Access
{
ACC_PUBLIC, /// public access
ACC_PROTECTED, /// protected access
ACC_PRIVATE /// private access
};
Symbol();
/// Creates the Symbol and assigns the symbol
/// a unique ID.
Symbol(const std::string& name, NameSpace* pNameSpace = 0);
/// Creates the Symbol and assigns the symbol
/// a unique ID.
virtual ~Symbol();
/// Destroys the Symbol.
int id() const;
/// Returns the symbol's unique ID.
const std::string& name() const;
/// Returns the symbol's (local) name.
NameSpace* nameSpace() const;
/// Returns the symbol's namespace which
/// may be null.
void setAccess(Access v);
/// Sets the symbol's access.
Access getAccess() const;
/// Returns the symbol's access.
void setDocumentation(const std::string& text);
/// Sets the symbol's documentation.
void addDocumentation(const std::string& text);
/// Adds text to the symbol's documentation.
const std::string& getDocumentation() const;
/// Returns the symbol's documentation.
void setFile(const std::string& path);
/// Sets the file where the symbol is declared.
const std::string& getFile() const;
/// Returns the file where the symbol is defined.
void setLineNumber(int line);
/// Sets the line number of the symbol's declaration.
int getLineNumber() const;
/// Returns the line number of the symbol's declaration.
void setPackage(const std::string& package);
/// Sets the symbol's package.
const std::string& getPackage() const;
/// Returns the symbol's package.
void setLibrary(const std::string& library);
/// Sets the symbol's library.
const std::string& getLibrary() const;
/// Returns the symbol's library.
const Attributes& attrs() const;
/// Returns the symbol's attributes.
Attributes& attrs();
/// Returns the symbol's attributes.
const Attributes& getAttributes() const;
/// Returns the symbol's attributes.
void setAttributes(const Attributes& attrs);
/// Sets the symbol's attributes.
std::string fullName() const;
/// Returns the symbol's fully qualified name.
static std::string extractName(const std::string& decl);
/// Extracts the name from the declaration.
virtual Kind kind() const = 0;
/// Returns the symbol's kind.
virtual std::string toString() const = 0;
/// Returns a string representation of the symbol.
bool isPublic() const;
/// Returns true iff the symbol is public.
bool isProtected() const;
/// Returns true iff the symbol is public.
bool isPrivate() const;
/// Returns true iff the symbol is public.
protected:
static bool isIdent(char c);
static bool hasAttr(const std::string& decl, const std::string& attr);
private:
Symbol(const Symbol&);
Symbol& operator = (const Symbol&);
int _id;
std::string _name;
NameSpace* _pNameSpace;
Access _access;
std::string _documentation;
std::string _file;
int _line;
std::string _package;
std::string _library;
Attributes _attrs;
static int _nextId;
};
//
// inlines
//
inline int Symbol::id() const
{
return _id;
}
inline const std::string& Symbol::name() const
{
return _name;
}
inline const std::string& Symbol::getDocumentation() const
{
return _documentation;
}
inline Symbol::Access Symbol::getAccess() const
{
return _access;
}
inline NameSpace* Symbol::nameSpace() const
{
return _pNameSpace;
}
inline const std::string& Symbol::getFile() const
{
return _file;
}
inline int Symbol::getLineNumber() const
{
return _line;
}
inline const std::string& Symbol::getPackage() const
{
return _package;
}
inline const std::string& Symbol::getLibrary() const
{
return _library;
}
inline const Attributes& Symbol::attrs() const
{
return _attrs;
}
inline Attributes& Symbol::attrs()
{
return _attrs;
}
inline bool Symbol::isPublic() const
{
return _access == ACC_PUBLIC;
}
inline bool Symbol::isProtected() const
{
return _access == ACC_PROTECTED;
}
inline bool Symbol::isPrivate() const
{
return _access == ACC_PRIVATE;
}
} } // namespace Poco::CppParser
#endif // CppParser_Symbol_INCLUDED

View File

@ -0,0 +1,44 @@
//
// Tokenizer.h
//
// Library: CppParser
// Package: CppParser
// Module: Tokenizer
//
// Definition of the Tokenizer class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Tokenizer_INCLUDED
#define CppParser_Tokenizer_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/StreamTokenizer.h"
namespace Poco {
namespace CppParser {
class CppParser_API Tokenizer: public Poco::StreamTokenizer
/// A Tokenizer for C++.
{
public:
Tokenizer(std::istream& istr);
/// Creates the Tokenizer.
~Tokenizer();
/// Destroys the Tokenizer.
};
} } // namespace Poco::CppParser
#endif // CppParser_Tokenizer_INCLUDED

View File

@ -0,0 +1,66 @@
//
// TypeDef.h
//
// Library: CppParser
// Package: SymbolTable
// Module: TypeDef
//
// Definition of the TypeDef class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_TypeDef_INCLUDED
#define CppParser_TypeDef_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Decl.h"
namespace Poco {
namespace CppParser {
class CppParser_API TypeDef: public Decl
/// This class represents a type definition (typedef).
{
public:
TypeDef(const std::string& decl, NameSpace* pNameSpace);
/// Creates the TypeDef.
~TypeDef();
/// Destroys the TypeDef.
Symbol::Kind kind() const;
std::string baseType() const;
/// Returns the underlying base type.
};
class CppParser_API TypeAlias: public Decl
/// This class represents a type alias definition (using).
{
public:
TypeAlias(const std::string& decl, NameSpace* pNameSpace);
/// Creates the TypeAlias.
~TypeAlias();
/// Destroys the TypeAlias.
Symbol::Kind kind() const;
std::string baseType() const;
/// Returns the underlying base type.
};
} } // namespace Poco::CppParser
#endif // CppParser_TypeDef_INCLUDED

View File

@ -0,0 +1,85 @@
//
// Utility.h
//
// Library: CppParser
// Package: CppParser
// Module: Utility
//
// Definition of the Utility class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Utility_INCLUDED
#define CppParser_Utility_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/NameSpace.h"
#include <vector>
#include <set>
namespace Poco {
namespace CppParser {
class CppParser_API Utility
/// Various helpers for parsing and analyzing C++ header files.
{
public:
class CppParser_API FwdDeclBlock
{
public:
std::string beginNameSpaceDecl; // contains either $(NS)_BEGIN or the namespace x { decl
std::string endNameSpaceDecl; // contains either $(NS)_END or the closing brackets }
std::vector<std::string> classDecls; // contains strings of the form "class X;"
};
static void parse(const std::string& file, NameSpace::SymbolTable& st, const std::string& exec, const std::string& options, const std::string& path);
/// Preprocesses and parses the file. The resulting symboltable has base class references already fixed,
static void 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);
/// Preprocesses and parses all files specified by the include pattern (e.g.: p:/poco/Foundation/include/*/*.h) minus the ones defined in the exclude pattern
static void fixup(NameSpace::SymbolTable& st);
/// Fixes all base pointers in the symbol table
static void detectPrefixAndIncludes(const std::string& origHFile, std::vector<std::string>& lines, std::string& prefix);
/// This method is poco coding style specific! It looks for a $(PREFIX)_BEGIN and extracts from it a prefix, also include files and fwd declarations are extracted from the h file.
static void removeFile(const std::string& preprocessedfile);
/// Tries to remove the file. If it fails, the error is silently ignored.
protected:
static std::string preprocessFile(const std::string& file, const std::string& exec, const std::string& options, const std::string& path);
/// Preprocess the include file with name file. Parameter exec must contain the name of the preprocessor binary (e.g.: "cl" for Visual Studio).
/// Parameter options contains the flag for the preprocessor, and parameter path sets the environment PATH settings during preprocessing.
/// Returns the name of the created file or throws an exception.
static void parseOnly(const std::string& file, NameSpace::SymbolTable& st, const std::string& preprocessedFile, bool removePreprocessedFile = true);
/// Parses the file, throws an exception if anything goes wrong.
static void buildFileList(std::set<std::string>& files, const std::vector<std::string>& includePattern, const std::vector<std::string>& excludePattern);
/// Searches all files that match the defined patterns and inserts them into files.
private:
Utility();
~Utility();
Utility(const Utility&);
Utility& operator=(const Utility&);
};
std::string CppParser_API replace(const std::string& input, const std::string& oldToken, const std::string& newToken);
/// Replaces in character input all oldTokens with the newToken
} } // namespace Poco::CppParser
#endif // CppParser_Utility_INCLUDED

View File

@ -0,0 +1,92 @@
//
// Variable.h
//
// Library: CppParser
// Package: SymbolTable
// Module: Variable
//
// Definition of the Variable class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Variable_INCLUDED
#define CppParser_Variable_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Decl.h"
namespace Poco {
namespace CppParser {
class CppParser_API Variable: public Decl
/// This class represents (member) variable declaration.
{
public:
enum Flags
{
VAR_STATIC = 1, /// The variable is static.
VAR_MUTABLE = 2, /// The variable is mutable.
VAR_VOLATILE = 4, /// The variable is volatile.
VAR_CONST = 8 /// The variable is const.
};
Variable(const std::string& decl, NameSpace* pNameSpace);
/// Creates the Variable.
~Variable();
/// Destroys the Variable.
int flags() const;
/// Returns the variable's flags.
bool isPointer() const;
/// Returns true iff the variable holds a pointer.
Symbol::Kind kind() const;
const std::string& declType() const;
/// Returns the type of the parameter without const and & if present.
///
/// Example: a type const std::string& -> std::string, a type const std::string* returns std::string
private:
int _flags;
bool _isPointer;
std::string _type;
};
//
// inlines
//
inline int Variable::flags() const
{
return _flags;
}
inline bool Variable::isPointer() const
{
return _isPointer;
}
inline const std::string& Variable::declType() const
{
return _type;
}
} } // namespace Poco::CppParser
#endif // CppParser_Variable_INCLUDED