forked from sanyaade-embedded-systems/Forge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCodeBlockNode.cpp
124 lines (94 loc) · 2.69 KB
/
CCodeBlockNode.cpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* CCodeBlockNode.cpp
* HyperCompiler
*
* Created by Uli Kusterer on 10.05.07.
* Copyright 2007 M. Uli Kusterer. All rights reserved.
*
*/
#include "CCodeBlockNode.h"
#include "CParser.h"
namespace Carlson
{
bool CCodeBlockNodeBase::LocalVariableExists( const std::string& inStr )
{
std::map<std::string,CVariableEntry>& locals = GetLocals();
return locals.find( inStr ) != locals.end();
}
void CCodeBlockNodeBase::DebugPrint( std::ostream& destStream, size_t indentLevel )
{
INDENT_PREPARE(indentLevel);
destStream << indentChars << "Code Block" << std::endl;
DebugPrintInner( destStream, indentLevel );
}
void CCodeBlockNodeBase::DebugPrintInner( std::ostream& destStream, size_t indentLevel )
{
INDENT_PREPARE(indentLevel);
destStream << indentChars << "{" << std::endl;
std::vector<CNode*>::iterator itty;
for( itty = mCommands.begin(); itty != mCommands.end(); itty++ )
{
(*itty)->DebugPrint( destStream, indentLevel +1 );
}
destStream << indentChars << "}" << std::endl;
}
void CCodeBlockNodeBase::Simplify()
{
CNode::Simplify();
std::vector<CNode*>::iterator itty;
for( itty = mCommands.begin(); itty != mCommands.end(); itty++ )
{
(*itty)->Simplify();
}
}
void CCodeBlockNodeBase::GenerateCode( CCodeBlock* inCodeBlock )
{
std::vector<CNode*>::iterator itty;
for( itty = mCommands.begin(); itty != mCommands.end(); itty++ )
{
(*itty)->GenerateCode( inCodeBlock );
}
}
CCodeBlockNodeBase::~CCodeBlockNodeBase()
{
std::vector<CNode*>::iterator itty;
for( itty = mCommands.begin(); itty != mCommands.end(); itty++ )
{
delete *itty;
*itty = NULL;
}
}
void CCodeBlockNode::AddLocalVar( const std::string& inName, const std::string& inUserName,
TVariantType theType, bool initWithName,
bool isParam, bool isGlobal,
bool dontDispose )
{
CVariableEntry newEntry( inUserName, theType, initWithName,
isParam, isGlobal, dontDispose );
std::map<std::string,CVariableEntry>::iterator foundVariable = (*mLocals).find( inName );
if( foundVariable == (*mLocals).end() )
(*mLocals)[inName] = newEntry;
if( isGlobal )
{
foundVariable = (*mGlobals).find( inName );
if( foundVariable == (*mGlobals).end() )
(*mGlobals)[inName] = newEntry;
}
}
long CCodeBlockNode::GetBPRelativeOffsetForLocalVar( const std::string& inName )
{
std::map<std::string,CVariableEntry>::iterator foundVariable = (*mLocals).find( inName );
if( foundVariable != (*mLocals).end() )
{
long bpRelOffs = foundVariable->second.mBPRelativeOffset;
if( bpRelOffs == LONG_MAX )
{
bpRelOffs = (*mLocalVariableCount)++;
foundVariable->second.mBPRelativeOffset = bpRelOffs;
}
return bpRelOffs;
}
else
return LONG_MAX;
}
} // namespace Carlson