/
CallFuncMacroExpTrans.java
60 lines (43 loc) · 1.71 KB
/
CallFuncMacroExpTrans.java
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
package org.overture.codegen.vdm2c.distribution.transformations;
import java.util.LinkedList;
import org.overture.cgc.extast.analysis.DepthFirstAnalysisCAdaptor;
import org.overture.codegen.ir.SExpIR;
import org.overture.codegen.ir.analysis.AnalysisException;
import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
import org.overture.codegen.ir.expressions.AIntLiteralExpIR;
import org.overture.codegen.trans.assistants.TransAssistantIR;
import org.overture.codegen.vdm2c.extast.expressions.AMacroApplyExpIR;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CallFuncMacroExpTrans extends DepthFirstAnalysisCAdaptor
{
final static Logger logger = LoggerFactory.getLogger(CallFuncMacroExpTrans.class);
public TransAssistantIR assist;
final static String retPrefix = "embeding_";
public CallFuncMacroExpTrans(TransAssistantIR assist)
{
this.assist = assist;
}
@Override
public void caseAMacroApplyExpIR(AMacroApplyExpIR node)
throws AnalysisException
{
if(node.getRoot() instanceof AIdentifierVarExpIR){
AIdentifierVarExpIR id_exp = (AIdentifierVarExpIR) node.getRoot();
if(id_exp.getName().equals("CALL_FUNC")){
int args_len = node.getArgs().size() - 4;
AIntLiteralExpIR a = new AIntLiteralExpIR();
a.setValue((long) args_len);
// get super type name
AIdentifierVarExpIR supTy = (AIdentifierVarExpIR) node.getArgs().get(1).clone();
supTy.setName("CLASS_ID_" + supTy.getName() + "_ID");
//supTy.set
node.getArgs().add(3, supTy);
// Add number of function arguments to second last position
node.getArgs().add(4, a);
// Transform name to distribution macro
id_exp.setName("DIST_CALL");
}
}
}
}