forked from ethereum/serpent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.h
105 lines (87 loc) · 3.05 KB
/
preprocess.h
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef ETHSERP_PREPROCESSOR
#define ETHSERP_PREPROCESSOR
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include "util.h"
#include "rewriteutils.h"
// Storage variable index storing object
struct svObj {
std::map<std::string, std::string> offsets;
std::map<std::string, int> indices;
std::map<std::string, std::vector<std::string> > coefficients;
std::map<std::string, bool> nonfinal;
std::string globalOffset;
};
// Grab the first 4 bytes
unsigned int getLeading4Bytes(std::vector<uint8_t> p);
class functionMetadata {
public:
functionMetadata(std::vector<uint8_t> _prefix=zeroes(32),
strvec _argTypes=strvec(), strvec _argNames=strvec(),
std::string _ot="int256",
std::vector<bool> _indexed=falses(0),
bool _constant=false) {
prefix = _prefix;
id = getLeading4Bytes(prefix);
argTypes = _argTypes;
argNames = _argNames;
outType = _ot;
indexed = _indexed;
if (!indexed.size()) indexed = falses(argNames.size());
ambiguous = false;
constant = _constant;
}
int id;
std::vector<uint8_t> prefix;
std::vector<std::string> argTypes;
std::vector<std::string> argNames;
std::vector<bool> indexed;
std::string outType;
bool ambiguous;
bool constant;
};
class typeMetadata {
public:
typeMetadata(std::string _name, strvec _inTypes, std::string _outType) {
name = _name;
inTypes = _inTypes;
outType = _outType;
}
std::string name;
strvec inTypes;
std::string outType;
};
// Get the function name and input and output types from a signature
typeMetadata getTypes(Node typeNode);
// Preprocessing result storing object
class preprocessAux {
public:
preprocessAux() {
}
std::map<std::string, functionMetadata> externs;
std::map<std::string, functionMetadata> interns;
std::map<std::string, functionMetadata> events;
std::map<int, rewriteRuleSet > customMacros;
std::map<std::string, std::string> types;
svObj storageVars;
};
#define preprocessResult std::pair<Node, preprocessAux>
// Populate an svObj with the arguments needed to determine
// the storage position of a node
svObj getStorageVars(svObj pre, Node node, std::string prefix="",
int index=0);
// Is the type a type of an array?
bool isArrayType(std::string type);
// Preprocess a function (see cpp for details)
preprocessResult preprocess(Node inp);
// Make a signature for a file
std::string mkExternLine(Node n);
// Make the javascript/solidity import signature for a contract
std::string mkFullExtern(Node n);
// Get the storage data mapping for a file
std::vector<Node> getDataNodes(Node n);
// Get the prefix int associated with a function name and set of argument types
unsigned int getPrefix(std::string functionName, strvec argTypes);
#endif