-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCCommandNode.cpp
More file actions
90 lines (68 loc) · 1.93 KB
/
Copy pathCCommandNode.cpp
File metadata and controls
90 lines (68 loc) · 1.93 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
/*
* CCommandNode.cpp
* HyperCompiler
*
* Created by Uli Kusterer on 10.05.07.
* Copyright 2007 M. Uli Kusterer. All rights reserved.
*
*/
#include "CCommandNode.h"
#include "CValueNode.h"
#include "CParseTree.h"
#include <assert.h>
#include "CNodeTransformation.h"
namespace Carlson
{
void CCommandNode::DebugPrint( std::ostream& destStream, size_t indentLevel )
{
INDENT_PREPARE(indentLevel);
destStream << indentChars << "Command \"" << mSymbolName << "\"" << std::endl
<< indentChars << "{" << std::endl;
std::vector<CValueNode*>::iterator itty;
for( itty = mParams.begin(); itty != mParams.end(); itty++ )
{
(*itty)->DebugPrint( destStream, indentLevel +1 );
}
destStream << indentChars << "}" << std::endl;
}
void CCommandNode::AddParam( CValueNode* val )
{
mParams.push_back( val );
mParseTree->NodeWasAdded(val);
}
void CCommandNode::Simplify()
{
CNode::Simplify();
std::vector<CValueNode*>::iterator itty;
for( itty = mParams.begin(); itty != mParams.end(); itty++ )
{
CValueNode * originalNode = *itty;
if( !originalNode )
continue;
originalNode->Simplify(); // Give subnodes a chance to apply transformations first. Might expose simpler sub-nodes we can then simplify.
CNode* newNode = CNodeTransformationBase::Apply( originalNode ); // Returns either originalNode, or a totally new object, in which case we delete the old one.
if( newNode != originalNode )
{
assert( dynamic_cast<CValueNode*>(newNode) != NULL );
*itty = (CValueNode*)newNode;
}
}
}
void CCommandNode::Visit( std::function<void(CNode*)> visitorBlock )
{
for( auto currParam : mParams )
{
if( currParam )
currParam->Visit( visitorBlock );
}
CNode::Visit( visitorBlock );
}
void CCommandNode::GenerateCode( CCodeBlock* inCodeBlock )
{
std::vector<CValueNode*>::iterator itty;
for( itty = mParams.begin(); itty != mParams.end(); itty++ )
{
(*itty)->GenerateCode( inCodeBlock );
}
}
} // namespace Carlson