2013-10-26 09:41:45 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-03-19 01:02:29 +01:00
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
2013-10-26 09:41:45 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CLASSCOMPILER_H
|
|
|
|
#define CLASSCOMPILER_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <istream>
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
struct ClassDebugInfo
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
int first_line;
|
|
|
|
int first_column;
|
|
|
|
int last_line;
|
|
|
|
int last_column;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FieldAccessorType
|
|
|
|
{
|
|
|
|
FTGet,
|
|
|
|
FTSet,
|
|
|
|
FTDefault
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FieldAccessor
|
|
|
|
{
|
|
|
|
FieldAccessorType Type;
|
|
|
|
std::string Accessor;
|
|
|
|
|
|
|
|
FieldAccessor(FieldAccessorType type, const std::string& accessor)
|
|
|
|
: Type(type), Accessor(accessor)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FieldAttribute
|
|
|
|
{
|
|
|
|
FAConfig = 1,
|
|
|
|
FAState = 2,
|
|
|
|
FAEnum = 4,
|
|
|
|
FAGetProtected = 8,
|
|
|
|
FASetProtected = 16
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Field
|
|
|
|
{
|
|
|
|
int Attributes;
|
|
|
|
std::string Type;
|
|
|
|
std::string Name;
|
|
|
|
std::string AlternativeName;
|
|
|
|
std::string GetAccessor;
|
|
|
|
std::string SetAccessor;
|
|
|
|
std::string DefaultAccessor;
|
|
|
|
|
|
|
|
std::string GetFriendlyName(void) const
|
|
|
|
{
|
|
|
|
if (!AlternativeName.empty())
|
|
|
|
return AlternativeName;
|
|
|
|
|
|
|
|
bool cap = true;
|
|
|
|
std::string name = Name;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < name.size(); i++) {
|
|
|
|
if (name[i] == '_') {
|
|
|
|
cap = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cap) {
|
|
|
|
name[i] = toupper(name[i]);
|
|
|
|
cap = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
name.erase(
|
|
|
|
std::remove(name.begin(), name.end(), '_'),
|
|
|
|
name.end()
|
|
|
|
);
|
|
|
|
|
|
|
|
/* TODO: figure out name */
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-18 10:18:57 +01:00
|
|
|
enum TypeAttribute
|
|
|
|
{
|
|
|
|
TAAbstract = 1,
|
|
|
|
TASafe = 2
|
|
|
|
};
|
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
struct Klass
|
|
|
|
{
|
|
|
|
std::string Name;
|
|
|
|
std::string Parent;
|
2013-12-18 10:18:57 +01:00
|
|
|
int Attributes;
|
2013-10-26 09:41:45 +02:00
|
|
|
std::vector<Field> Fields;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClassCompiler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ClassCompiler(const std::string& path, std::istream *input);
|
|
|
|
~ClassCompiler(void);
|
|
|
|
|
|
|
|
void Compile(void);
|
|
|
|
|
|
|
|
std::string GetPath(void) const;
|
|
|
|
|
|
|
|
void InitializeScanner(void);
|
|
|
|
void DestroyScanner(void);
|
|
|
|
|
|
|
|
void *GetScanner(void);
|
|
|
|
|
|
|
|
size_t ReadInput(char *buffer, size_t max_size);
|
|
|
|
|
|
|
|
void HandleInclude(const std::string& path, const ClassDebugInfo& locp);
|
|
|
|
void HandleAngleInclude(const std::string& path, const ClassDebugInfo& locp);
|
|
|
|
void HandleClass(const Klass& klass, const ClassDebugInfo& locp);
|
|
|
|
void HandleNamespaceBegin(const std::string& name, const ClassDebugInfo& locp);
|
|
|
|
void HandleNamespaceEnd(const ClassDebugInfo& locp);
|
|
|
|
void HandleCode(const std::string& code, const ClassDebugInfo& locp);
|
|
|
|
|
|
|
|
static void CompileFile(const std::string& path);
|
|
|
|
static void CompileStream(const std::string& path, std::istream *stream);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_Path;
|
|
|
|
std::istream *m_Input;
|
|
|
|
void *m_Scanner;
|
2013-12-13 12:54:14 +01:00
|
|
|
|
|
|
|
static unsigned long SDBM(const std::string& str, size_t len);
|
2013-10-26 09:41:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-03 10:41:30 +01:00
|
|
|
#endif /* CLASSCOMPILER_H */
|
|
|
|
|