-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCPutCommandNode.cpp
69 lines (61 loc) · 2.03 KB
/
CPutCommandNode.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
/*
* CPutCommandNode.cpp
* Forge
*
* Created by Uli Kusterer on 18.12.10.
* Copyright 2010 Uli Kusterer. All rights reserved.
*
*/
#include "CPutCommandNode.h"
#include "CValueNode.h"
#include "CCodeBlock.h"
#include "CMakeChunkRefNode.h"
#include "CObjectPropertyNode.h"
#include "CGlobalPropertyNode.h"
#include "LEOInstructions.h"
#include <iostream>
namespace Carlson
{
void CPutCommandNode::GenerateCode( CCodeBlock* inCodeBlock )
{
CValueNode * destValue = GetParamAtIndex( 1 );
CValueNode * srcValue = GetParamAtIndex( 0 );
CMakeChunkRefNode * chunkValue = NULL;
CObjectPropertyNode * propertyValue = NULL;
CGlobalPropertyNode * globalPropertyValue = NULL;
if(( chunkValue = dynamic_cast<CMakeChunkRefNode*>(destValue) ))
{
destValue->GenerateCode( inCodeBlock );
srcValue->GenerateCode( inCodeBlock );
inCodeBlock->GenerateSetStringInstruction( BACK_OF_STACK );
}
else if(( propertyValue = dynamic_cast<CObjectPropertyNode*>(destValue) ))
{
std::string propName;
propertyValue->GetSymbolName(propName);
if( propName.length() > 0 )
inCodeBlock->GeneratePushStringInstruction( propName );
else
propertyValue->GetParamAtIndex( 1 )->GenerateCode( inCodeBlock );
propertyValue->GetParamAtIndex( 0 )->GenerateCode( inCodeBlock );
if( !srcValue )
throw CForgeParseError("Expected a value to assign to the given property.", GetLineNum());
srcValue->GenerateCode( inCodeBlock );
inCodeBlock->GenerateSetPropertyOfObjectInstruction();
}
else if(( globalPropertyValue = dynamic_cast<CGlobalPropertyNode*>(destValue) ))
{
globalPropertyValue->GenerateSetterCode( inCodeBlock, srcValue );
}
else
{
if( !destValue )
throw CForgeParseError("Expected a destination for this assignment statement.", GetLineNum());
destValue->GenerateCode( inCodeBlock );
if( !srcValue )
throw CForgeParseError("Expected a value to assign to the given property.", GetLineNum());
srcValue->GenerateCode( inCodeBlock );
inCodeBlock->GeneratePutValueIntoValueInstruction();
}
}
} // namespace Carlson