skittles 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/abi/get-abi.js +67 -10
- package/lib/compiler/skittles-compiler.d.ts +2 -0
- package/lib/compiler/skittles-compiler.js +35 -0
- package/lib/data/constants.d.ts +1 -0
- package/lib/data/constants.js +4 -0
- package/lib/data/yul-template.d.ts +1 -0
- package/lib/data/yul-template.js +7 -0
- package/lib/dependencies/add-dependencies.d.ts +3 -0
- package/lib/dependencies/add-dependencies.js +29 -0
- package/lib/helpers/ast-helper.js +2 -1
- package/lib/helpers/file-helper.d.ts +1 -0
- package/lib/helpers/file-helper.js +20 -8
- package/lib/index.d.ts +2 -1
- package/lib/index.js +5 -24
- package/lib/skittles-class/get-skittles-class.js +17 -4
- package/lib/skittles-class/get-skittles-constructor.d.ts +2 -2
- package/lib/skittles-class/get-skittles-constructor.js +3 -3
- package/lib/skittles-class/get-skittles-expression.d.ts +2 -2
- package/lib/skittles-class/get-skittles-expression.js +117 -56
- package/lib/skittles-class/get-skittles-interfaces.d.ts +4 -0
- package/lib/skittles-class/get-skittles-interfaces.js +47 -0
- package/lib/skittles-class/get-skittles-method.d.ts +2 -2
- package/lib/skittles-class/get-skittles-method.js +9 -9
- package/lib/skittles-class/get-skittles-operator.js +2 -0
- package/lib/skittles-class/get-skittles-property.d.ts +2 -2
- package/lib/skittles-class/get-skittles-property.js +5 -3
- package/lib/skittles-class/get-skittles-state-mutability.js +1 -1
- package/lib/skittles-class/get-skittles-statements.d.ts +2 -2
- package/lib/skittles-class/get-skittles-statements.js +139 -34
- package/lib/skittles-class/get-skittles-type.d.ts +2 -1
- package/lib/skittles-class/get-skittles-type.js +54 -18
- package/lib/types/skittles-class.d.ts +96 -20
- package/lib/types/skittles-class.js +30 -11
- package/lib/yul/add-yul-method-dispatcher.js +30 -9
- package/lib/yul/add-yul-method-function.js +15 -4
- package/lib/yul/add-yul-property-dispatcher.js +21 -1
- package/lib/yul/add-yul-storage-access.js +32 -4
- package/lib/yul/add-yul-storage-layout.d.ts +6 -2
- package/lib/yul/add-yul-storage-layout.js +41 -16
- package/lib/yul/add-yul-value-initialzations.js +3 -2
- package/lib/yul/get-expression-yul.js +16 -1
- package/lib/yul/get-statement-yul.js +55 -3
- package/lib/yul/get-yul.js +7 -5
- package/lib/yul/yul-constants.js +1 -0
- package/package.json +1 -1
package/lib/abi/get-abi.js
CHANGED
|
@@ -1,37 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const skittles_class_1 = require("../types/skittles-class");
|
|
4
|
+
const getTypeString = (type) => {
|
|
5
|
+
return type.kind;
|
|
6
|
+
};
|
|
3
7
|
const getConstructorAbi = (constructor) => {
|
|
4
8
|
if (!constructor)
|
|
5
9
|
return [];
|
|
6
10
|
return [
|
|
7
11
|
{
|
|
8
12
|
type: "constructor",
|
|
9
|
-
inputs: constructor.parameters.map((i) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
inputs: constructor.parameters.map((i) => {
|
|
14
|
+
return {
|
|
15
|
+
name: i.name,
|
|
16
|
+
type: getTypeString(i.type),
|
|
17
|
+
};
|
|
18
|
+
}),
|
|
13
19
|
stateMutability: "nonpayable",
|
|
14
20
|
},
|
|
15
21
|
];
|
|
16
22
|
};
|
|
17
23
|
const getPropertyAbi = (property) => {
|
|
24
|
+
if (property.type.kind === skittles_class_1.SkittlesTypeKind.Mapping) {
|
|
25
|
+
return {
|
|
26
|
+
type: "function",
|
|
27
|
+
name: property.name,
|
|
28
|
+
inputs: property.type.inputs.map((i) => {
|
|
29
|
+
return {
|
|
30
|
+
name: "",
|
|
31
|
+
type: getTypeString(i),
|
|
32
|
+
};
|
|
33
|
+
}),
|
|
34
|
+
outputs: [{ name: "", type: getTypeString(property.type.output) }],
|
|
35
|
+
stateMutability: "view",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (property.type.kind === skittles_class_1.SkittlesTypeKind.Array) {
|
|
39
|
+
return {
|
|
40
|
+
type: "function",
|
|
41
|
+
name: property.name,
|
|
42
|
+
inputs: [
|
|
43
|
+
{
|
|
44
|
+
name: "index",
|
|
45
|
+
type: "uint256",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
outputs: [{ name: "", type: getTypeString(property.type.itemType) }],
|
|
49
|
+
stateMutability: "view",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
18
52
|
return {
|
|
19
53
|
type: "function",
|
|
20
54
|
name: property.name,
|
|
21
55
|
inputs: [],
|
|
22
|
-
outputs: [{ name: "", type: property.type }],
|
|
56
|
+
outputs: [{ name: "", type: getTypeString(property.type) }],
|
|
23
57
|
stateMutability: "view",
|
|
24
58
|
};
|
|
25
59
|
};
|
|
26
60
|
const getMethodAbi = (method) => {
|
|
61
|
+
const outputs = () => {
|
|
62
|
+
const { returns } = method;
|
|
63
|
+
if (returns.kind === skittles_class_1.SkittlesTypeKind.Void)
|
|
64
|
+
return [];
|
|
65
|
+
if (returns.kind === skittles_class_1.SkittlesTypeKind.Interface) {
|
|
66
|
+
return [
|
|
67
|
+
...returns.interface.elements.map((e) => {
|
|
68
|
+
return {
|
|
69
|
+
name: e.name,
|
|
70
|
+
type: getTypeString(e.type),
|
|
71
|
+
};
|
|
72
|
+
}),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
return [
|
|
76
|
+
{
|
|
77
|
+
name: "",
|
|
78
|
+
type: getTypeString(returns),
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
};
|
|
27
82
|
return {
|
|
28
83
|
type: "function",
|
|
29
84
|
name: method.name,
|
|
30
|
-
inputs: method.parameters.map((i) =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
85
|
+
inputs: method.parameters.map((i) => {
|
|
86
|
+
return {
|
|
87
|
+
name: i.name,
|
|
88
|
+
type: getTypeString(i.type),
|
|
89
|
+
};
|
|
90
|
+
}),
|
|
91
|
+
outputs: outputs(),
|
|
35
92
|
stateMutability: method.view ? "view" : "payable",
|
|
36
93
|
};
|
|
37
94
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ora_1 = __importDefault(require("ora"));
|
|
7
|
+
const get_abi_1 = __importDefault(require("../abi/get-abi"));
|
|
8
|
+
const get_bytecode_1 = __importDefault(require("../bytecode/get-bytecode"));
|
|
9
|
+
const add_dependencies_1 = __importDefault(require("../dependencies/add-dependencies"));
|
|
10
|
+
const file_helper_1 = require("../helpers/file-helper");
|
|
11
|
+
const get_skittles_class_1 = __importDefault(require("../skittles-class/get-skittles-class"));
|
|
12
|
+
const get_yul_1 = __importDefault(require("../yul/get-yul"));
|
|
13
|
+
const doTask = (task, fn) => {
|
|
14
|
+
const spinner = (0, ora_1.default)(task).start();
|
|
15
|
+
const response = fn();
|
|
16
|
+
spinner.succeed();
|
|
17
|
+
return response;
|
|
18
|
+
};
|
|
19
|
+
const skittlesCompile = () => {
|
|
20
|
+
const files = doTask("Loading Contracts", () => (0, file_helper_1.getAllContractFiles)());
|
|
21
|
+
const classes = doTask("Processing", () => files.map(get_skittles_class_1.default));
|
|
22
|
+
classes.forEach((skittlesClass) => {
|
|
23
|
+
const { name } = skittlesClass;
|
|
24
|
+
doTask(`Compiling ${name}`, () => {
|
|
25
|
+
const newClass = (0, add_dependencies_1.default)(skittlesClass, classes);
|
|
26
|
+
const abi = (0, get_abi_1.default)(newClass);
|
|
27
|
+
(0, file_helper_1.writeFile)("abi", name, JSON.stringify(abi, null, 2));
|
|
28
|
+
const yul = (0, get_yul_1.default)(newClass, abi);
|
|
29
|
+
(0, file_helper_1.writeFile)("yul", name, yul);
|
|
30
|
+
const bytecode = (0, get_bytecode_1.default)(name, yul);
|
|
31
|
+
(0, file_helper_1.writeFile)("bytecode", name, bytecode);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.default = skittlesCompile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
@@ -2,6 +2,7 @@ export declare enum YulSection {
|
|
|
2
2
|
Constructor = "constructor",
|
|
3
3
|
Dispatchers = "dispatchers",
|
|
4
4
|
Functions = "functions",
|
|
5
|
+
ConstructorFunctions = "constructor functions",
|
|
5
6
|
StorageLayout = "storage layout",
|
|
6
7
|
ConstructorStorageLayout = "constructor storage layout",
|
|
7
8
|
StorageAccess = "storage access",
|
package/lib/data/yul-template.js
CHANGED
|
@@ -6,6 +6,7 @@ var YulSection;
|
|
|
6
6
|
YulSection["Constructor"] = "constructor";
|
|
7
7
|
YulSection["Dispatchers"] = "dispatchers";
|
|
8
8
|
YulSection["Functions"] = "functions";
|
|
9
|
+
YulSection["ConstructorFunctions"] = "constructor functions";
|
|
9
10
|
YulSection["StorageLayout"] = "storage layout";
|
|
10
11
|
YulSection["ConstructorStorageLayout"] = "constructor storage layout";
|
|
11
12
|
YulSection["StorageAccess"] = "storage access";
|
|
@@ -54,6 +55,9 @@ const yulTemplate = [
|
|
|
54
55
|
`/* ---------- constructor ----------- */`,
|
|
55
56
|
``,
|
|
56
57
|
``,
|
|
58
|
+
`/* ---------- constructor functions ----------- */`,
|
|
59
|
+
``,
|
|
60
|
+
``,
|
|
57
61
|
`/* -------- constructor storage layout ---------- */`,
|
|
58
62
|
``,
|
|
59
63
|
``,
|
|
@@ -108,6 +112,9 @@ const yulTemplate = [
|
|
|
108
112
|
`mstore(64, v)`,
|
|
109
113
|
`return(0x00, 0x60)`,
|
|
110
114
|
`}`,
|
|
115
|
+
`function returnArray(v) {`,
|
|
116
|
+
`return(0, v)`,
|
|
117
|
+
`}`,
|
|
111
118
|
`function returnBoolean(v) {`,
|
|
112
119
|
`switch v`,
|
|
113
120
|
`case true {`,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const addDependencies = (skittlesClass, classes) => {
|
|
4
|
+
const dependencyClasses = classes.filter((c) => {
|
|
5
|
+
return skittlesClass.classExtensions.includes(c.name);
|
|
6
|
+
});
|
|
7
|
+
if (dependencyClasses.length === 0)
|
|
8
|
+
return skittlesClass;
|
|
9
|
+
const { name, constructor, methods, interfaces, variables, classExtensions } = skittlesClass;
|
|
10
|
+
dependencyClasses.forEach((dependencyClass) => {
|
|
11
|
+
const { methods: dependencyMethods, interfaces: dependencyInterfaces, variables: dependencyVariables, classExtensions: dependencyClassExtensions, } = dependencyClass;
|
|
12
|
+
Object.entries(dependencyInterfaces).forEach(([key, value]) => {
|
|
13
|
+
if (!interfaces[key])
|
|
14
|
+
interfaces[key] = value;
|
|
15
|
+
});
|
|
16
|
+
methods.push(...dependencyMethods);
|
|
17
|
+
variables.push(...dependencyVariables);
|
|
18
|
+
classExtensions.push(...dependencyClassExtensions);
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
classExtensions,
|
|
22
|
+
name,
|
|
23
|
+
constructor,
|
|
24
|
+
methods,
|
|
25
|
+
interfaces,
|
|
26
|
+
variables,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.default = addDependencies;
|
|
@@ -48,7 +48,8 @@ exports.isFalseKeyword = isFalseKeyword;
|
|
|
48
48
|
const isNodePrivate = (node) => {
|
|
49
49
|
let isPrivate = false;
|
|
50
50
|
(0, typescript_1.forEachChild)(node, (node) => {
|
|
51
|
-
if (node.kind === typescript_1.SyntaxKind.PrivateKeyword
|
|
51
|
+
if (node.kind === typescript_1.SyntaxKind.PrivateKeyword ||
|
|
52
|
+
node.kind === typescript_1.SyntaxKind.ProtectedKeyword) {
|
|
52
53
|
isPrivate = true;
|
|
53
54
|
}
|
|
54
55
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const getAllFilesInDirectory: (dir: string) => string[];
|
|
1
2
|
export declare const getAllContractFiles: () => string[];
|
|
2
3
|
export declare const writeFile: (type: string, fileName: string, content: string) => void;
|
|
3
4
|
export declare const clearDirectory: (directory: string) => void;
|
|
@@ -3,21 +3,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getContractName = exports.clearDirectory = exports.writeFile = exports.getAllContractFiles = void 0;
|
|
6
|
+
exports.getContractName = exports.clearDirectory = exports.writeFile = exports.getAllContractFiles = exports.getAllFilesInDirectory = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const CONTRCT_PATH = "./contracts";
|
|
10
|
+
const getAllFilesInDirectory = (dir) => {
|
|
11
|
+
const files = [];
|
|
12
|
+
fs_1.default.readdirSync(dir).forEach((file) => {
|
|
13
|
+
const filePath = path_1.default.join(dir, file);
|
|
14
|
+
if (fs_1.default.statSync(filePath).isDirectory()) {
|
|
15
|
+
files.push(...(0, exports.getAllFilesInDirectory)(filePath));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
files.push(filePath);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return files;
|
|
22
|
+
};
|
|
23
|
+
exports.getAllFilesInDirectory = getAllFilesInDirectory;
|
|
10
24
|
const getAllContractFiles = () => {
|
|
11
|
-
return
|
|
12
|
-
.readdirSync(CONTRCT_PATH)
|
|
25
|
+
return (0, exports.getAllFilesInDirectory)(CONTRCT_PATH)
|
|
13
26
|
.filter((file) => {
|
|
14
|
-
return fs_1.default.statSync(
|
|
15
|
-
})
|
|
16
|
-
.map((file) => {
|
|
17
|
-
return path_1.default.join(CONTRCT_PATH, file);
|
|
27
|
+
return fs_1.default.statSync(file).isFile();
|
|
18
28
|
})
|
|
19
29
|
.filter((file) => {
|
|
20
|
-
return file.endsWith(".ts")
|
|
30
|
+
return (file.endsWith(".ts") &&
|
|
31
|
+
!file.endsWith(".d.ts") &&
|
|
32
|
+
!file.endsWith(".spec.ts"));
|
|
21
33
|
});
|
|
22
34
|
};
|
|
23
35
|
exports.getAllContractFiles = getAllContractFiles;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { address, self, block, chain, msg, tx } from "./types/core-types";
|
|
3
3
|
import getSkittlesFactory from "./testing/get-skittles-factory";
|
|
4
|
-
|
|
4
|
+
import { ZERO_ADDRESS } from "./data/constants";
|
|
5
|
+
export { address, self, block, chain, msg, tx, getSkittlesFactory, ZERO_ADDRESS, };
|
package/lib/index.js
CHANGED
|
@@ -13,13 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.getSkittlesFactory = exports.tx = exports.msg = exports.chain = exports.block = exports.self = void 0;
|
|
16
|
+
exports.ZERO_ADDRESS = exports.getSkittlesFactory = exports.tx = exports.msg = exports.chain = exports.block = exports.self = void 0;
|
|
17
17
|
const yargs_1 = __importDefault(require("yargs"));
|
|
18
|
-
const get_abi_1 = __importDefault(require("./abi/get-abi"));
|
|
19
|
-
const get_bytecode_1 = __importDefault(require("./bytecode/get-bytecode"));
|
|
20
18
|
const file_helper_1 = require("./helpers/file-helper");
|
|
21
|
-
const get_skittles_class_1 = __importDefault(require("./skittles-class/get-skittles-class"));
|
|
22
|
-
const get_yul_1 = __importDefault(require("./yul/get-yul"));
|
|
23
19
|
const core_types_1 = require("./types/core-types");
|
|
24
20
|
Object.defineProperty(exports, "self", { enumerable: true, get: function () { return core_types_1.self; } });
|
|
25
21
|
Object.defineProperty(exports, "block", { enumerable: true, get: function () { return core_types_1.block; } });
|
|
@@ -29,28 +25,13 @@ Object.defineProperty(exports, "tx", { enumerable: true, get: function () { retu
|
|
|
29
25
|
const get_skittles_factory_1 = __importDefault(require("./testing/get-skittles-factory"));
|
|
30
26
|
exports.getSkittlesFactory = get_skittles_factory_1.default;
|
|
31
27
|
const console_helper_1 = require("./helpers/console-helper");
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const files = (0, file_helper_1.getAllContractFiles)();
|
|
36
|
-
filesSpinner.succeed();
|
|
37
|
-
files.forEach((file) => {
|
|
38
|
-
const name = (0, file_helper_1.getContractName)(file);
|
|
39
|
-
const spinner = (0, ora_1.default)(`Compiling ${name}`).start();
|
|
40
|
-
const skittlesClass = (0, get_skittles_class_1.default)(file);
|
|
41
|
-
const abi = (0, get_abi_1.default)(skittlesClass);
|
|
42
|
-
(0, file_helper_1.writeFile)("abi", name, JSON.stringify(abi, null, 2));
|
|
43
|
-
const yul = (0, get_yul_1.default)(skittlesClass, abi);
|
|
44
|
-
(0, file_helper_1.writeFile)("yul", name, yul);
|
|
45
|
-
const bytecode = (0, get_bytecode_1.default)(name, yul);
|
|
46
|
-
(0, file_helper_1.writeFile)("bytecode", name, bytecode);
|
|
47
|
-
spinner.succeed();
|
|
48
|
-
});
|
|
49
|
-
};
|
|
28
|
+
const skittles_compiler_1 = __importDefault(require("./compiler/skittles-compiler"));
|
|
29
|
+
const constants_1 = require("./data/constants");
|
|
30
|
+
Object.defineProperty(exports, "ZERO_ADDRESS", { enumerable: true, get: function () { return constants_1.ZERO_ADDRESS; } });
|
|
50
31
|
yargs_1.default
|
|
51
32
|
.command("compile", "Compile all TypeScript files", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
33
|
(0, console_helper_1.logSkittles)();
|
|
53
|
-
|
|
34
|
+
(0, skittles_compiler_1.default)();
|
|
54
35
|
}))
|
|
55
36
|
.command("clean", "Clears the cache and deletes all builds", () => {
|
|
56
37
|
(0, file_helper_1.clearDirectory)("./build");
|
|
@@ -7,12 +7,14 @@ const typescript_1 = require("typescript");
|
|
|
7
7
|
const get_ast_1 = __importDefault(require("../ast/get-ast"));
|
|
8
8
|
const ast_helper_1 = require("../helpers/ast-helper");
|
|
9
9
|
const get_skittles_constructor_1 = __importDefault(require("./get-skittles-constructor"));
|
|
10
|
+
const get_skittles_interfaces_1 = __importDefault(require("./get-skittles-interfaces"));
|
|
10
11
|
const get_skittles_method_1 = __importDefault(require("./get-skittles-method"));
|
|
11
12
|
const get_skittles_property_1 = __importDefault(require("./get-skittles-property"));
|
|
12
13
|
const get_skittles_state_mutability_1 = __importDefault(require("./get-skittles-state-mutability"));
|
|
13
14
|
const getSkittlesClass = (file) => {
|
|
14
15
|
const ast = (0, get_ast_1.default)(file);
|
|
15
16
|
const classNode = (0, ast_helper_1.getClassNode)(ast);
|
|
17
|
+
const interfaces = (0, get_skittles_interfaces_1.default)(ast);
|
|
16
18
|
const astVariables = classNode.members
|
|
17
19
|
.filter(typescript_1.isPropertyDeclaration)
|
|
18
20
|
.filter(ast_helper_1.isVariable);
|
|
@@ -21,15 +23,26 @@ const getSkittlesClass = (file) => {
|
|
|
21
23
|
.filter(typescript_1.isPropertyDeclaration)
|
|
22
24
|
.filter(ast_helper_1.isPropertyArrowFunction);
|
|
23
25
|
const astConstructor = classNode.members.find(typescript_1.isConstructorDeclaration);
|
|
26
|
+
const classExtensions = [];
|
|
27
|
+
const { heritageClauses } = classNode;
|
|
28
|
+
if (heritageClauses) {
|
|
29
|
+
heritageClauses.forEach((heritageClause) => {
|
|
30
|
+
heritageClause.types.forEach((type) => {
|
|
31
|
+
classExtensions.push((0, ast_helper_1.getNodeName)(type.expression));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
24
35
|
const skittlesClass = {
|
|
36
|
+
classExtensions,
|
|
37
|
+
interfaces,
|
|
25
38
|
name: (0, ast_helper_1.getNodeName)(classNode),
|
|
26
39
|
constructor: astConstructor
|
|
27
|
-
? (0, get_skittles_constructor_1.default)(astConstructor)
|
|
40
|
+
? (0, get_skittles_constructor_1.default)(astConstructor, interfaces)
|
|
28
41
|
: undefined,
|
|
29
|
-
variables: astVariables.map(get_skittles_property_1.default),
|
|
42
|
+
variables: astVariables.map((v) => (0, get_skittles_property_1.default)(v, interfaces)),
|
|
30
43
|
methods: [
|
|
31
|
-
...astMethods.map(get_skittles_method_1.default),
|
|
32
|
-
...astArrowFunctions.map(get_skittles_method_1.default),
|
|
44
|
+
...astMethods.map((m) => (0, get_skittles_method_1.default)(m, interfaces)),
|
|
45
|
+
...astArrowFunctions.map((f) => (0, get_skittles_method_1.default)(f, interfaces)),
|
|
33
46
|
],
|
|
34
47
|
};
|
|
35
48
|
return (0, get_skittles_state_mutability_1.default)(skittlesClass);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ConstructorDeclaration } from "typescript";
|
|
2
|
-
import { SkittlesConstructor } from "../types/skittles-class";
|
|
3
|
-
declare const getSkittlesConstructor: (astConstructor: ConstructorDeclaration) => SkittlesConstructor;
|
|
2
|
+
import { SkittlesConstructor, SkittlesInterfaces } from "../types/skittles-class";
|
|
3
|
+
declare const getSkittlesConstructor: (astConstructor: ConstructorDeclaration, interfaces: SkittlesInterfaces) => SkittlesConstructor;
|
|
4
4
|
export default getSkittlesConstructor;
|
|
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const ast_helper_1 = require("../helpers/ast-helper");
|
|
7
7
|
const get_skittles_statements_1 = __importDefault(require("./get-skittles-statements"));
|
|
8
8
|
const get_skittles_type_1 = __importDefault(require("./get-skittles-type"));
|
|
9
|
-
const getSkittlesConstructor = (astConstructor) => {
|
|
9
|
+
const getSkittlesConstructor = (astConstructor, interfaces) => {
|
|
10
10
|
return {
|
|
11
11
|
parameters: astConstructor.parameters.map((parameter) => {
|
|
12
12
|
return {
|
|
13
13
|
name: (0, ast_helper_1.getNodeName)(parameter),
|
|
14
|
-
type: (0, get_skittles_type_1.default)(parameter.type),
|
|
14
|
+
type: (0, get_skittles_type_1.default)(parameter.type, interfaces),
|
|
15
15
|
};
|
|
16
16
|
}),
|
|
17
|
-
statements: (0, get_skittles_statements_1.default)(astConstructor.body, (0, get_skittles_type_1.default)(astConstructor.type)),
|
|
17
|
+
statements: (0, get_skittles_statements_1.default)(astConstructor.body, (0, get_skittles_type_1.default)(astConstructor.type, interfaces), interfaces),
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
exports.default = getSkittlesConstructor;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Expression } from "typescript";
|
|
2
|
-
import { SkittlesExpression } from "../types/skittles-class";
|
|
3
|
-
declare const getSkittlesExpression: (expression: Expression) => SkittlesExpression;
|
|
2
|
+
import { SkittlesExpression, SkittlesInterfaces } from "../types/skittles-class";
|
|
3
|
+
declare const getSkittlesExpression: (expression: Expression, interfaces: SkittlesInterfaces) => SkittlesExpression;
|
|
4
4
|
export default getSkittlesExpression;
|
|
@@ -8,87 +8,148 @@ const ast_helper_1 = require("../helpers/ast-helper");
|
|
|
8
8
|
const skittles_class_1 = require("../types/skittles-class");
|
|
9
9
|
const get_skittles_operator_1 = __importDefault(require("./get-skittles-operator"));
|
|
10
10
|
const get_skittles_type_1 = __importDefault(require("./get-skittles-type"));
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const getIdentifierExpression = (expression) => {
|
|
12
|
+
return {
|
|
13
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Variable,
|
|
14
|
+
value: expression.escapedText,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const getLiteralExpression = (expression, interfaces) => {
|
|
18
|
+
const value = expression.text;
|
|
19
|
+
return {
|
|
20
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Value,
|
|
21
|
+
type: (0, get_skittles_type_1.default)(expression, interfaces, value),
|
|
22
|
+
value,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const getPropertyAccessExpression = (expression, interfaces) => {
|
|
26
|
+
if (expression.expression.kind === typescript_1.SyntaxKind.PropertyAccessExpression) {
|
|
27
|
+
const property = (0, ast_helper_1.getNodeName)(expression);
|
|
28
|
+
switch (property) {
|
|
29
|
+
case "length":
|
|
30
|
+
return {
|
|
31
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Length,
|
|
32
|
+
value: getSkittlesExpression(expression.expression, interfaces),
|
|
33
|
+
};
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unknown property access property: ${property}`);
|
|
36
|
+
}
|
|
17
37
|
}
|
|
18
|
-
if (
|
|
19
|
-
const value = expression.text;
|
|
38
|
+
if (expression.expression.kind === typescript_1.SyntaxKind.ThisKeyword) {
|
|
20
39
|
return {
|
|
21
|
-
expressionType: skittles_class_1.SkittlesExpressionType.
|
|
22
|
-
|
|
23
|
-
value,
|
|
40
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Storage,
|
|
41
|
+
variable: (0, ast_helper_1.getNodeName)(expression),
|
|
24
42
|
};
|
|
25
43
|
}
|
|
26
|
-
if (
|
|
27
|
-
|
|
44
|
+
if (expression.expression.kind === typescript_1.SyntaxKind.Identifier) {
|
|
45
|
+
const environment = expression.expression.escapedText;
|
|
46
|
+
if (!environment)
|
|
47
|
+
throw new Error("Could not get environment");
|
|
48
|
+
if (["block", "chain", "msg", "tx"].includes(environment)) {
|
|
28
49
|
return {
|
|
29
|
-
expressionType: skittles_class_1.SkittlesExpressionType.
|
|
50
|
+
expressionType: skittles_class_1.SkittlesExpressionType.EvmDialect,
|
|
51
|
+
environment: environment,
|
|
30
52
|
variable: (0, ast_helper_1.getNodeName)(expression),
|
|
31
53
|
};
|
|
32
54
|
}
|
|
33
|
-
if (
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
36
|
-
throw new Error("Could not get environment");
|
|
37
|
-
if (["block", "chain", "msg", "tx"].includes(environment)) {
|
|
55
|
+
if (environment === "Number") {
|
|
56
|
+
const element = (0, ast_helper_1.getNodeName)(expression.name);
|
|
57
|
+
if (element === "MAX_SAFE_INTEGER" || element === "MAX_VALUE") {
|
|
38
58
|
return {
|
|
39
|
-
expressionType: skittles_class_1.SkittlesExpressionType.
|
|
40
|
-
|
|
41
|
-
|
|
59
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Value,
|
|
60
|
+
type: {
|
|
61
|
+
kind: skittles_class_1.SkittlesTypeKind.Number,
|
|
62
|
+
},
|
|
63
|
+
value: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
|
42
64
|
};
|
|
43
65
|
}
|
|
44
|
-
throw new Error(`
|
|
66
|
+
throw new Error(`Could not get value for ${element}`);
|
|
45
67
|
}
|
|
46
|
-
throw new Error(`
|
|
68
|
+
throw new Error(`Unknown environment: ${environment}`);
|
|
69
|
+
}
|
|
70
|
+
throw new Error(`Property access expression not supported ${expression.kind}`);
|
|
71
|
+
};
|
|
72
|
+
const getBinaryExpression = (expression, interfaces) => {
|
|
73
|
+
return {
|
|
74
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Binary,
|
|
75
|
+
left: getSkittlesExpression(expression.left, interfaces),
|
|
76
|
+
right: getSkittlesExpression(expression.right, interfaces),
|
|
77
|
+
operator: (0, get_skittles_operator_1.default)(expression.operatorToken.kind),
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const getElementAccessExpression = (expression, interfaces) => {
|
|
81
|
+
let e = expression;
|
|
82
|
+
const items = [];
|
|
83
|
+
while ((0, typescript_1.isElementAccessExpression)(e)) {
|
|
84
|
+
items.unshift(getSkittlesExpression(e.argumentExpression, interfaces));
|
|
85
|
+
e = e.expression;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Mapping,
|
|
89
|
+
variable: (0, ast_helper_1.getNodeName)(e),
|
|
90
|
+
items,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const getPrefixUnaryExpression = (expression, interfaces) => {
|
|
94
|
+
return {
|
|
95
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Not,
|
|
96
|
+
value: getSkittlesExpression(expression.operand, interfaces),
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
const getBooleanExpression = (item) => {
|
|
100
|
+
return {
|
|
101
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Value,
|
|
102
|
+
type: { kind: skittles_class_1.SkittlesTypeKind.Void },
|
|
103
|
+
value: item ? "true" : "false",
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const getThisExpression = () => {
|
|
107
|
+
return {
|
|
108
|
+
expressionType: skittles_class_1.SkittlesExpressionType.This,
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const getNewExpression = (expression, interfaces) => {
|
|
112
|
+
var _a;
|
|
113
|
+
return {
|
|
114
|
+
expressionType: skittles_class_1.SkittlesExpressionType.Deploy,
|
|
115
|
+
contract: (0, ast_helper_1.getNodeName)(expression.expression),
|
|
116
|
+
parameters: ((_a = expression.arguments) === null || _a === void 0 ? void 0 : _a.map((arg) => getSkittlesExpression(arg, interfaces))) || [],
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
const getSkittlesExpression = (expression, interfaces) => {
|
|
120
|
+
if ((0, typescript_1.isIdentifier)(expression)) {
|
|
121
|
+
return getIdentifierExpression(expression);
|
|
122
|
+
}
|
|
123
|
+
if ((0, typescript_1.isLiteralExpression)(expression)) {
|
|
124
|
+
return getLiteralExpression(expression, interfaces);
|
|
125
|
+
}
|
|
126
|
+
if ((0, typescript_1.isPropertyAccessExpression)(expression)) {
|
|
127
|
+
return getPropertyAccessExpression(expression, interfaces);
|
|
47
128
|
}
|
|
48
129
|
if ((0, typescript_1.isBinaryExpression)(expression)) {
|
|
49
|
-
return
|
|
50
|
-
expressionType: skittles_class_1.SkittlesExpressionType.Binary,
|
|
51
|
-
left: getSkittlesExpression(expression.left),
|
|
52
|
-
right: getSkittlesExpression(expression.right),
|
|
53
|
-
operator: (0, get_skittles_operator_1.default)(expression.operatorToken.kind),
|
|
54
|
-
};
|
|
130
|
+
return getBinaryExpression(expression, interfaces);
|
|
55
131
|
}
|
|
56
132
|
if ((0, typescript_1.isElementAccessExpression)(expression)) {
|
|
57
|
-
|
|
58
|
-
while ((0, typescript_1.isElementAccessExpression)(expression)) {
|
|
59
|
-
items.unshift(getSkittlesExpression(expression.argumentExpression));
|
|
60
|
-
expression = expression.expression;
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
expressionType: skittles_class_1.SkittlesExpressionType.Mapping,
|
|
64
|
-
variable: (0, ast_helper_1.getNodeName)(expression),
|
|
65
|
-
items,
|
|
66
|
-
};
|
|
133
|
+
return getElementAccessExpression(expression, interfaces);
|
|
67
134
|
}
|
|
68
135
|
if ((0, typescript_1.isParenthesizedExpression)(expression)) {
|
|
69
|
-
return getSkittlesExpression(expression.expression);
|
|
136
|
+
return getSkittlesExpression(expression.expression, interfaces);
|
|
70
137
|
}
|
|
71
138
|
if ((0, typescript_1.isPrefixUnaryExpression)(expression)) {
|
|
72
|
-
return
|
|
73
|
-
expressionType: skittles_class_1.SkittlesExpressionType.Not,
|
|
74
|
-
value: getSkittlesExpression(expression.operand),
|
|
75
|
-
};
|
|
139
|
+
return getPrefixUnaryExpression(expression, interfaces);
|
|
76
140
|
}
|
|
77
141
|
if ((0, ast_helper_1.isTrueKeyword)(expression)) {
|
|
78
|
-
return
|
|
79
|
-
expressionType: skittles_class_1.SkittlesExpressionType.Value,
|
|
80
|
-
type: "bool",
|
|
81
|
-
value: "true",
|
|
82
|
-
};
|
|
142
|
+
return getBooleanExpression(true);
|
|
83
143
|
}
|
|
84
144
|
if ((0, ast_helper_1.isFalseKeyword)(expression)) {
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
145
|
+
return getBooleanExpression(false);
|
|
146
|
+
}
|
|
147
|
+
if (expression.kind === typescript_1.SyntaxKind.ThisKeyword) {
|
|
148
|
+
return getThisExpression();
|
|
149
|
+
}
|
|
150
|
+
if ((0, typescript_1.isNewExpression)(expression)) {
|
|
151
|
+
return getNewExpression(expression, interfaces);
|
|
90
152
|
}
|
|
91
|
-
console.log(JSON.stringify(expression));
|
|
92
153
|
throw new Error(`Unknown expression type: ${expression.kind}`);
|
|
93
154
|
};
|
|
94
155
|
exports.default = getSkittlesExpression;
|