[r368]: cmajor++ / Cm / Cm.Core / Exception.hpp Maximize Restore History

Download this file

Exception.hpp    101 lines (85 with data), 4.0 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
/*========================================================================
Copyright (c) 2012-2013 Seppo Laakko
http://sourceforge.net/projects/cmajor/
Distributed under the GNU General Public License, version 3 (GPLv3).
(See accompanying LICENSE.txt or http://www.gnu.org/licenses/gpl.html)
========================================================================*/
#ifndef CM_CORE_EXCEPTION_INCLUDED
#define CM_CORE_EXCEPTION_INCLUDED
#include <Cm.Core/Variable.hpp>
#include <map>
namespace Cm { namespace Core {
class Function;
typedef std::shared_ptr<Function> FunctionPtr;
class FunctionCall;
typedef std::shared_ptr<FunctionCall> FunctionCallPtr;
class ExceptionHandler;
typedef std::shared_ptr<ExceptionHandler> ExceptionHandlerPtr;
typedef std::vector<ExceptionHandlerPtr> ExceptionHandlerList;
class ExceptionHandler: public Object
{
public:
ExceptionHandler(const Position& pos_, const ScopePtr& enclosingScope_, const ScopePtr& fileScope_, const ObjectPtr& exceptionTypeExpr_,
const std::string& exceptionVarName_, const CompoundStatementPtr& catchBlock_);
virtual void Dispose();
virtual ObjectPtr Clone(CloneContext& context) const;
ObjectPtr ExceptionTypeExpr() const { return exceptionTypeExpr; }
const std::string& ExceptionVarName() const { return exceptionVarName; }
const CompoundStatementPtr& CatchBlock() const { return catchBlock; }
TypePtr CatchedBy() const { return catchType; }
TypePtr Catches() const { return exceptionBaseType; }
virtual void SetCompound(CompoundStatement* compound);
virtual void TypeCheckBody(TypeCheckContext& context);
virtual void CollectLocalVariables(LocalVariableList& vars);
virtual void GenerateDestructionStatements(DestructionStackPtr destructionStack);
virtual void SetFunction(Function* function);
void SetNextHandler(ExceptionHandlerPtr next_) { next = next_; }
ExceptionHandlerPtr Next() const { return next; }
private:
ObjectPtr exceptionTypeExpr;
std::string exceptionVarName;
TypePtr catchType;
TypePtr exceptionBaseType;
CompoundStatementPtr catchBlock;
ExceptionHandlerPtr next;
};
ExceptionHandlerList CloneExceptionHandlers(const ExceptionHandlerList& handlers, CloneContext& context);
class ExceptionTable;
typedef std::shared_ptr<ExceptionTable> ExceptionTablePtr;
enum class ExceptionTypeSource
{
library, project
};
class ExceptionTable
{
public:
static void Init();
static void Done();
static ExceptionTablePtr Instance();
void AddExceptionType(TypePtr exceptionType, ExceptionTypeSource source);
void GenerateLibraryDeclarations(CodeFormatter& formatter);
void GenerateExceptionTables(CodeFormatter& formatter);
void Store(const std::string& exceptionTypeFileName);
void Load(const std::string& exceptionTypeFileName);
ObjectPtr GetNumExceptionsConstant() const { return numExceptionsConstant; }
ObjectPtr GetExceptionBaseIdTableAddrConstant() const { return exceptionBaseIdTableAddrConstant; }
ObjectPtr GetExceptionTableAddrConstant() const { return exceptionTableAddrConstant; }
ObjectPtr GetExceptionIdConstant(TypePtr exceptionType) const;
private:
ExceptionTable();
static ExceptionTablePtr instance;
static std::stack<ExceptionTablePtr> instanceStack;
typedef std::set<std::pair<TypePtr, ExceptionTypeSource>> ExceptionTypeSet;
typedef ExceptionTypeSet::const_iterator ExceptionTypeSetIt;
ExceptionTypeSet exceptionTypes;
std::string numExceptionsConstantName;
ObjectPtr numExceptionsConstant;
std::string exceptionBaseIdTableAddrConstantName;
ObjectPtr exceptionBaseIdTableAddrConstant;
std::string exceptionTableAddrConstantName;
ObjectPtr exceptionTableAddrConstant;
};
void ExceptionInit();
void ExceptionDone();
} } // namespace Cm::Core
#endif // CM_CORE_EXCEPTION_INCLUDED