forked from PlatONnetwork/pWASM-abigen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplate.cpp
More file actions
43 lines (39 loc) · 1.32 KB
/
Template.cpp
File metadata and controls
43 lines (39 loc) · 1.32 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
//
// Created by zhou.yang on 2018/10/9.
//
#include "Template.h"
using namespace std;
namespace platon {
string generateAbiCPlusPlus(ContractDef &contractDef, ABIDef &abiDef) {
string code = "//platon autogen begin\n";
code += "extern \"C\" { \n";
for (auto method : abiDef.abis) {
code += method.returnType.realTypeName + " ";
code += method.methodName + "(";
for (int i = 0; i < method.args.size(); ++i) {
code += method.types[i].realTypeName + " ";
code += method.args[i];
if (i != method.args.size()-1) {
code += ",";
}
}
code += ") {\n";
code += contractDef.fullName + " ";
string var = contractDef.name + "_platon";
code += var + ";\n";
if (method.returnType.realTypeName != "void"){
code += "return ";
}
code += var + "." + method.methodName + "(";
for (int i = 0; i < method.args.size(); ++i) {
code += method.args[i];
if (i != method.args.size()-1) {
code += ",";
}
}
code += ");\n}\n";
}
code += "\n}\n//platon autogen end";
return code;
}
}