Repository navigation
Expand file tree
/
Copy pathCreationException.h
More file actions
108 lines (86 loc) · 2.13 KB
/
Copy pathCreationException.h
File metadata and controls
108 lines (86 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Created by Ivan Buhov on 9/4/15.
//
#pragma once
#include "MetaEntities.h"
#include "TypeEntities.h"
#include <clang/AST/Type.h>
#include <string>
#define DEFINE_POLYMORPHIC_THROW \
virtual void polymorhicThrow() override { \
throw *this; \
}
#define POLYMORPHIC_THROW(ex) do \
{ \
ex->polymorhicThrow(); \
throw std::logic_error("polymorphicThrow should never return"); \
} while(false)
namespace Meta {
class CreationException {
public:
static std::string constructMessage(std::string outerMessage, std::string innerMessage)
{
return outerMessage + " --> " + innerMessage;
}
CreationException(std::string message, bool isError)
: _message(message)
, _isError(isError)
{
}
virtual ~CreationException() { }
virtual void polymorhicThrow() = 0;
std::string getMessage() const
{
return _message;
}
virtual std::string getDetailedMessage() const
{
return getMessage();
}
bool isError() const
{
return _isError;
}
private:
std::string _message;
bool _isError;
};
class MetaCreationException : public CreationException {
public:
MetaCreationException(const Meta* meta, std::string message, bool isError)
: CreationException(message, isError)
, _meta(meta)
{
}
std::string getDetailedMessage() const override
{
return _meta->identificationString() + " : " + this->getMessage();
}
const Meta* getMeta()
{
return _meta;
}
DEFINE_POLYMORPHIC_THROW;
private:
const Meta* _meta;
};
class TypeCreationException : public CreationException {
public:
TypeCreationException(const clang::Type* type, std::string message, bool isError)
: CreationException(message, isError)
, _type(type)
{
}
std::string getDetailedMessage() const override
{
return std::string("[Type ") + (_type == nullptr ? "" : _type->getTypeClassName()) + "] : " + this->getMessage();
}
const clang::Type* getType()
{
return _type;
}
DEFINE_POLYMORPHIC_THROW;
private:
const clang::Type* _type;
};
}