1 /*
2  * The contents of this file are subject to the Mozilla Public License
3  * Version 1.0 (the "License"); you may not use this file except in
4  * compliance with the License. You may obtain a copy of the License at
5  * http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9  * License for the specific language governing rights and limitations
10  * under the License.
11  *
12  * The Initial Developer of this code is David Baum.
13  * Portions created by David Baum are Copyright (C) 1998 David Baum.
14  * All Rights Reserved.
15  *
16  * Portions created by John Hansen are Copyright (C) 2005 John Hansen.
17  * All Rights Reserved.
18  *
19  */
20 
21 #include <cstring>
22 #include "AssignStmt.h"
23 #include "RCX_Cmd.h"
24 #include "Bytecode.h"
25 #include "Expr.h"
26 #include "RCX_Target.h"
27 #include "Error.h"
28 
AssignStmt(Expr * lval,Expr * value)29 AssignStmt::AssignStmt(Expr *lval, Expr * value)
30  :	fLval(lval),
31 	fValue(value)
32 {
33 }
34 
35 
~AssignStmt()36 AssignStmt::~AssignStmt()
37 {
38 	delete fLval;
39 	delete fValue;
40 }
41 
42 
EmitActual(Bytecode & b)43 void AssignStmt::EmitActual(Bytecode &b)
44 {
45 	RCX_Value dst = fLval->EmitAny(b);
46 	int type = RCX_VALUE_TYPE(dst);
47 
48  	if (type == kRCX_VariableType)
49 	{
50                 fValue->EmitTo(b, RCX_VALUE_DATA(dst));
51 	}
52 	else
53 	{
54 		if (b.GetTarget()->SourceWritable(type))
55 		{
56 			RCX_Cmd cmd;
57 			RCX_Value ea = fValue->EmitAny(b);
58 
59 			cmd.MakeSet(dst, ea);
60 			b.Add(cmd);
61 
62 			b.ReleaseTempEA(ea);
63 		}
64 		else
65 			Error(kErr_LValueNeeded).Raise(&fLval->GetLoc());
66 
67 	}
68 
69 	b.ReleaseTempEA(dst); // ea may be an array with temp index
70 }
71 
72 
CloneActual(Mapping * m) const73 Stmt* AssignStmt::CloneActual(Mapping *m) const
74 {
75 	return new AssignStmt(fLval->Clone(m), fValue->Clone(m));
76 }
77 
78 
GetExprs(vector<Expr * > & v) const79 void AssignStmt::GetExprs(vector<Expr *> &v) const
80 {
81 	v.push_back(fLval);
82 	v.push_back(fValue);
83 }
84