cashc 0.7.0-next.0 → 0.7.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/dist/main/Errors.d.ts +10 -7
- package/dist/main/Errors.js +19 -13
- package/dist/main/artifact/Artifact.d.ts +1 -1
- package/dist/main/artifact/Artifact.js +3 -3
- package/dist/main/ast/AST.d.ts +7 -6
- package/dist/main/ast/AST.js +2 -1
- package/dist/main/ast/AstBuilder.d.ts +5 -5
- package/dist/main/ast/AstBuilder.js +84 -82
- package/dist/main/ast/AstTraversal.d.ts +2 -2
- package/dist/main/ast/AstTraversal.js +2 -2
- package/dist/main/ast/AstVisitor.d.ts +1 -1
- package/dist/main/ast/Globals.d.ts +4 -1
- package/dist/main/ast/Globals.js +22 -18
- package/dist/main/ast/Location.d.ts +1 -1
- package/dist/main/ast/Pragma.d.ts +1 -1
- package/dist/main/ast/SymbolTable.d.ts +1 -1
- package/dist/main/ast/ThrowingErrorListener.js +3 -3
- package/dist/main/cashc-cli.js +9 -9
- package/dist/main/compiler.d.ts +1 -1
- package/dist/main/compiler.js +20 -20
- package/dist/main/generation/GenerateTargetTraversal.d.ts +2 -2
- package/dist/main/generation/GenerateTargetTraversal.js +37 -37
- package/dist/main/generation/utils.d.ts +2 -2
- package/dist/main/generation/utils.js +55 -55
- package/dist/main/grammar/CashScriptLexer.d.ts +16 -15
- package/dist/main/grammar/CashScriptLexer.js +373 -363
- package/dist/main/grammar/CashScriptListener.d.ts +11 -0
- package/dist/main/grammar/CashScriptParser.d.ts +29 -18
- package/dist/main/grammar/CashScriptParser.js +468 -390
- package/dist/main/grammar/CashScriptVisitor.d.ts +7 -0
- package/dist/main/index.d.ts +2 -2
- package/dist/main/index.js +9 -5
- package/dist/main/print/OutputSourceCodeTraversal.d.ts +2 -2
- package/dist/main/print/OutputSourceCodeTraversal.js +3 -3
- package/dist/main/semantic/EnsureFinalRequireTraversal.d.ts +2 -2
- package/dist/main/semantic/EnsureFinalRequireTraversal.js +9 -9
- package/dist/main/semantic/SymbolTableTraversal.d.ts +3 -2
- package/dist/main/semantic/SymbolTableTraversal.js +36 -27
- package/dist/main/semantic/TypeCheckTraversal.d.ts +2 -2
- package/dist/main/semantic/TypeCheckTraversal.js +67 -67
- package/dist/module/Errors.d.ts +10 -7
- package/dist/module/Errors.js +7 -2
- package/dist/module/artifact/Artifact.d.ts +1 -1
- package/dist/module/artifact/Artifact.js +1 -1
- package/dist/module/ast/AST.d.ts +7 -6
- package/dist/module/ast/AST.js +2 -1
- package/dist/module/ast/AstBuilder.d.ts +5 -5
- package/dist/module/ast/AstBuilder.js +10 -8
- package/dist/module/ast/AstTraversal.d.ts +2 -2
- package/dist/module/ast/AstTraversal.js +1 -1
- package/dist/module/ast/AstVisitor.d.ts +1 -1
- package/dist/module/ast/Globals.d.ts +4 -1
- package/dist/module/ast/Globals.js +5 -1
- package/dist/module/ast/Location.d.ts +1 -1
- package/dist/module/ast/Pragma.d.ts +1 -1
- package/dist/module/ast/SymbolTable.d.ts +1 -1
- package/dist/module/ast/ThrowingErrorListener.js +2 -2
- package/dist/module/cashc-cli.js +1 -1
- package/dist/module/compiler.d.ts +1 -1
- package/dist/module/compiler.js +9 -9
- package/dist/module/generation/GenerateTargetTraversal.d.ts +2 -2
- package/dist/module/generation/GenerateTargetTraversal.js +5 -5
- package/dist/module/generation/utils.d.ts +2 -2
- package/dist/module/generation/utils.js +2 -2
- package/dist/module/grammar/CashScriptLexer.d.ts +16 -15
- package/dist/module/grammar/CashScriptLexer.js +368 -362
- package/dist/module/grammar/CashScriptListener.d.ts +11 -0
- package/dist/module/grammar/CashScriptParser.d.ts +29 -18
- package/dist/module/grammar/CashScriptParser.js +461 -388
- package/dist/module/grammar/CashScriptVisitor.d.ts +7 -0
- package/dist/module/index.d.ts +2 -2
- package/dist/module/index.js +2 -2
- package/dist/module/print/OutputSourceCodeTraversal.d.ts +2 -2
- package/dist/module/print/OutputSourceCodeTraversal.js +1 -1
- package/dist/module/semantic/EnsureFinalRequireTraversal.d.ts +2 -2
- package/dist/module/semantic/EnsureFinalRequireTraversal.js +3 -3
- package/dist/module/semantic/SymbolTableTraversal.d.ts +3 -2
- package/dist/module/semantic/SymbolTableTraversal.js +16 -7
- package/dist/module/semantic/TypeCheckTraversal.d.ts +2 -2
- package/dist/module/semantic/TypeCheckTraversal.js +6 -6
- package/package.json +2 -2
package/dist/main/Errors.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Type
|
|
2
|
-
import { IdentifierNode, FunctionDefinitionNode, VariableDefinitionNode, ParameterNode, Node, FunctionCallNode, BinaryOpNode, UnaryOpNode, TimeOpNode, CastNode, AssignNode, BranchNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, StatementNode, ContractNode, ExpressionNode } from './ast/AST';
|
|
3
|
-
import { Symbol, SymbolType } from './ast/SymbolTable';
|
|
4
|
-
import { Location, Point } from './ast/Location';
|
|
1
|
+
import { Type } from '@cashscript/utils';
|
|
2
|
+
import { IdentifierNode, FunctionDefinitionNode, VariableDefinitionNode, ParameterNode, Node, FunctionCallNode, BinaryOpNode, UnaryOpNode, TimeOpNode, CastNode, AssignNode, BranchNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, StatementNode, ContractNode, ExpressionNode } from './ast/AST.js';
|
|
3
|
+
import { Symbol, SymbolType } from './ast/SymbolTable.js';
|
|
4
|
+
import { Location, Point } from './ast/Location.js';
|
|
5
5
|
export declare class CashScriptError extends Error {
|
|
6
6
|
node: Node;
|
|
7
7
|
constructor(node: Node, message: string);
|
|
@@ -45,9 +45,9 @@ export declare class FinalRequireStatementError extends CashScriptError {
|
|
|
45
45
|
constructor(node: StatementNode);
|
|
46
46
|
}
|
|
47
47
|
export declare class TypeError extends CashScriptError {
|
|
48
|
-
actual?:
|
|
49
|
-
expected?:
|
|
50
|
-
constructor(node: Node, actual?:
|
|
48
|
+
actual?: Type | Type[] | undefined;
|
|
49
|
+
expected?: Type | Type[] | undefined;
|
|
50
|
+
constructor(node: Node, actual?: Type | Type[] | undefined, expected?: Type | Type[] | undefined, message?: string);
|
|
51
51
|
}
|
|
52
52
|
export declare class InvalidParameterTypeError extends TypeError {
|
|
53
53
|
constructor(node: FunctionCallNode | RequireNode | InstantiationNode, actual: Type[], expected: Type[]);
|
|
@@ -73,6 +73,9 @@ export declare class TupleAssignmentError extends CashScriptError {
|
|
|
73
73
|
export declare class ConstantConditionError extends CashScriptError {
|
|
74
74
|
constructor(node: BranchNode | RequireNode, res: boolean);
|
|
75
75
|
}
|
|
76
|
+
export declare class ConstantModificationError extends CashScriptError {
|
|
77
|
+
constructor(node: VariableDefinitionNode);
|
|
78
|
+
}
|
|
76
79
|
export declare class ArrayElementError extends CashScriptError {
|
|
77
80
|
constructor(node: ArrayNode);
|
|
78
81
|
}
|
package/dist/main/Errors.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VersionError = exports.IndexOutOfBoundsError = exports.ArrayElementError = exports.ConstantConditionError = exports.TupleAssignmentError = exports.AssignTypeError = exports.CastSizeError = exports.CastTypeError = exports.UnsupportedTypeError = exports.UnequalTypeError = exports.InvalidParameterTypeError = exports.TypeError = exports.FinalRequireStatementError = exports.EmptyFunctionError = exports.EmptyContractError = exports.UnusedVariableError = exports.VariableRedefinitionError = exports.FunctionRedefinitionError = exports.RedefinitionError = exports.InvalidSymbolTypeError = exports.UndefinedReferenceError = exports.ParseError = exports.CashScriptError = void 0;
|
|
3
|
+
exports.VersionError = exports.IndexOutOfBoundsError = exports.ArrayElementError = exports.ConstantModificationError = exports.ConstantConditionError = exports.TupleAssignmentError = exports.AssignTypeError = exports.CastSizeError = exports.CastTypeError = exports.UnsupportedTypeError = exports.UnequalTypeError = exports.InvalidParameterTypeError = exports.TypeError = exports.FinalRequireStatementError = exports.EmptyFunctionError = exports.EmptyContractError = exports.UnusedVariableError = exports.VariableRedefinitionError = exports.FunctionRedefinitionError = exports.RedefinitionError = exports.InvalidSymbolTypeError = exports.UndefinedReferenceError = exports.ParseError = exports.CashScriptError = void 0;
|
|
4
4
|
const utils_1 = require("@cashscript/utils");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const AST_js_1 = require("./ast/AST.js");
|
|
6
|
+
const Location_js_1 = require("./ast/Location.js");
|
|
7
7
|
class CashScriptError extends Error {
|
|
8
8
|
constructor(node, message) {
|
|
9
9
|
if (node.location) {
|
|
@@ -17,7 +17,7 @@ class CashScriptError extends Error {
|
|
|
17
17
|
exports.CashScriptError = CashScriptError;
|
|
18
18
|
class ParseError extends Error {
|
|
19
19
|
constructor(message, location) {
|
|
20
|
-
const start = location instanceof
|
|
20
|
+
const start = location instanceof Location_js_1.Point ? location : location === null || location === void 0 ? void 0 : location.start;
|
|
21
21
|
if (start) {
|
|
22
22
|
message += ` at ${start}`;
|
|
23
23
|
}
|
|
@@ -97,7 +97,7 @@ class TypeError extends CashScriptError {
|
|
|
97
97
|
exports.TypeError = TypeError;
|
|
98
98
|
class InvalidParameterTypeError extends TypeError {
|
|
99
99
|
constructor(node, actual, expected) {
|
|
100
|
-
const name = node instanceof
|
|
100
|
+
const name = node instanceof AST_js_1.RequireNode ? 'require' : node.identifier.name;
|
|
101
101
|
super(node, actual, expected, `Found parameters (${actual}) in call to function '${name}' where parameters (${expected}) were expected`);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -112,7 +112,7 @@ class UnequalTypeError extends TypeError {
|
|
|
112
112
|
exports.UnequalTypeError = UnequalTypeError;
|
|
113
113
|
class UnsupportedTypeError extends TypeError {
|
|
114
114
|
constructor(node, actual, expected) {
|
|
115
|
-
if (node instanceof
|
|
115
|
+
if (node instanceof AST_js_1.BinaryOpNode && node.operator.startsWith('.')) {
|
|
116
116
|
if (expected === utils_1.PrimitiveType.INT) {
|
|
117
117
|
super(node, actual, expected, `Tried to call member 'split' with unsupported parameter type '${actual}'`);
|
|
118
118
|
}
|
|
@@ -120,23 +120,23 @@ class UnsupportedTypeError extends TypeError {
|
|
|
120
120
|
super(node, actual, expected, `Tried to call member 'split' on unsupported type '${actual}'`);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
else if (node instanceof
|
|
123
|
+
else if (node instanceof AST_js_1.BinaryOpNode) {
|
|
124
124
|
super(node, actual, expected, `Tried to apply operator '${node.operator}' to unsupported type '${actual}'`);
|
|
125
125
|
}
|
|
126
|
-
else if (node instanceof
|
|
126
|
+
else if (node instanceof AST_js_1.UnaryOpNode && node.operator.startsWith('.')) {
|
|
127
127
|
super(node, actual, expected, `Tried to access member '${node.operator}' on unsupported type '${actual}'`);
|
|
128
128
|
}
|
|
129
|
-
else if (node instanceof
|
|
129
|
+
else if (node instanceof AST_js_1.UnaryOpNode && node.operator.includes('[i]')) {
|
|
130
130
|
const [scope] = node.operator.split('[i]');
|
|
131
131
|
super(node, actual, expected, `Tried to index '${scope}''with unsupported type '${actual}'`);
|
|
132
132
|
}
|
|
133
|
-
else if (node instanceof
|
|
133
|
+
else if (node instanceof AST_js_1.UnaryOpNode) {
|
|
134
134
|
super(node, actual, expected, `Tried to apply operator '${node.operator}' to unsupported type '${actual}'`);
|
|
135
135
|
}
|
|
136
|
-
else if (node instanceof
|
|
136
|
+
else if (node instanceof AST_js_1.TimeOpNode) {
|
|
137
137
|
super(node, actual, expected, `Tried to apply operator '>=' on unsupported type '${actual}'`);
|
|
138
138
|
}
|
|
139
|
-
else if (node instanceof
|
|
139
|
+
else if (node instanceof AST_js_1.TupleIndexOpNode) {
|
|
140
140
|
super(node, actual, expected, `Tried to index unsupported type '${actual}'`);
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
@@ -159,7 +159,7 @@ class CastSizeError extends CashScriptError {
|
|
|
159
159
|
exports.CastSizeError = CastSizeError;
|
|
160
160
|
class AssignTypeError extends TypeError {
|
|
161
161
|
constructor(node) {
|
|
162
|
-
const expected = node instanceof
|
|
162
|
+
const expected = node instanceof AST_js_1.AssignNode ? node.identifier.type : node.type;
|
|
163
163
|
super(node, node.expression.type, expected, `Type '${node.expression.type}' can not be assigned to variable of type '${expected}'`);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
@@ -176,6 +176,12 @@ class ConstantConditionError extends CashScriptError {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
exports.ConstantConditionError = ConstantConditionError;
|
|
179
|
+
class ConstantModificationError extends CashScriptError {
|
|
180
|
+
constructor(node) {
|
|
181
|
+
super(node, `Tried to modify immutable variable '${node.name}'`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.ConstantModificationError = ConstantModificationError;
|
|
179
185
|
class ArrayElementError extends CashScriptError {
|
|
180
186
|
constructor(node) {
|
|
181
187
|
super(node, 'Incorrect elements in array');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateArtifact = void 0;
|
|
4
4
|
const utils_1 = require("@cashscript/utils");
|
|
5
|
-
const
|
|
5
|
+
const index_js_1 = require("../index.js");
|
|
6
6
|
function generateArtifact(ast, script, source) {
|
|
7
7
|
const { contract } = ast;
|
|
8
8
|
const constructorInputs = contract.parameters
|
|
@@ -14,7 +14,7 @@ function generateArtifact(ast, script, source) {
|
|
|
14
14
|
type: parameter.type.toString(),
|
|
15
15
|
})),
|
|
16
16
|
}));
|
|
17
|
-
const bytecode = utils_1.scriptToAsm(script);
|
|
17
|
+
const bytecode = (0, utils_1.scriptToAsm)(script);
|
|
18
18
|
return {
|
|
19
19
|
contractName: contract.name,
|
|
20
20
|
constructorInputs,
|
|
@@ -23,7 +23,7 @@ function generateArtifact(ast, script, source) {
|
|
|
23
23
|
source,
|
|
24
24
|
compiler: {
|
|
25
25
|
name: 'cashc',
|
|
26
|
-
version:
|
|
26
|
+
version: index_js_1.version,
|
|
27
27
|
},
|
|
28
28
|
updatedAt: new Date().toISOString(),
|
|
29
29
|
};
|
package/dist/main/ast/AST.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Type } from '@cashscript/utils';
|
|
2
|
-
import { TimeOp } from './Globals';
|
|
3
|
-
import AstVisitor from './AstVisitor';
|
|
4
|
-
import { BinaryOperator, NullaryOperator, UnaryOperator } from './Operator';
|
|
5
|
-
import { Location } from './Location';
|
|
6
|
-
import { SymbolTable, Symbol } from './SymbolTable';
|
|
2
|
+
import { TimeOp } from './Globals.js';
|
|
3
|
+
import AstVisitor from './AstVisitor.js';
|
|
4
|
+
import { BinaryOperator, NullaryOperator, UnaryOperator } from './Operator.js';
|
|
5
|
+
import { Location } from './Location.js';
|
|
6
|
+
import { SymbolTable, Symbol } from './SymbolTable.js';
|
|
7
7
|
export declare type Ast = SourceFileNode;
|
|
8
8
|
export declare abstract class Node {
|
|
9
9
|
location?: Location;
|
|
@@ -47,9 +47,10 @@ export declare abstract class StatementNode extends Node {
|
|
|
47
47
|
}
|
|
48
48
|
export declare class VariableDefinitionNode extends StatementNode implements Named, Typed {
|
|
49
49
|
type: Type;
|
|
50
|
+
modifier: string;
|
|
50
51
|
name: string;
|
|
51
52
|
expression: ExpressionNode;
|
|
52
|
-
constructor(type: Type, name: string, expression: ExpressionNode);
|
|
53
|
+
constructor(type: Type, modifier: string, name: string, expression: ExpressionNode);
|
|
53
54
|
accept<T>(visitor: AstVisitor<T>): T;
|
|
54
55
|
}
|
|
55
56
|
export declare class TupleAssignmentNode extends StatementNode {
|
package/dist/main/ast/AST.js
CHANGED
|
@@ -55,9 +55,10 @@ class StatementNode extends Node {
|
|
|
55
55
|
}
|
|
56
56
|
exports.StatementNode = StatementNode;
|
|
57
57
|
class VariableDefinitionNode extends StatementNode {
|
|
58
|
-
constructor(type, name, expression) {
|
|
58
|
+
constructor(type, modifier, name, expression) {
|
|
59
59
|
super();
|
|
60
60
|
this.type = type;
|
|
61
|
+
this.modifier = modifier;
|
|
61
62
|
this.name = name;
|
|
62
63
|
this.expression = expression;
|
|
63
64
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
|
|
2
|
-
import { ParseTree } from 'antlr4ts/tree/ParseTree';
|
|
3
|
-
import { Node, SourceFileNode, ContractNode, ParameterNode, VariableDefinitionNode, FunctionDefinitionNode, AssignNode, IdentifierNode, BranchNode, CastNode, FunctionCallNode, UnaryOpNode, BinaryOpNode, BoolLiteralNode, IntLiteralNode, HexLiteralNode, StringLiteralNode, ExpressionNode, LiteralNode, BlockNode, TimeOpNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, TupleAssignmentNode, NullaryOpNode } from './AST';
|
|
4
|
-
import { ContractDefinitionContext, FunctionDefinitionContext, VariableDefinitionContext, TupleAssignmentContext, ParameterContext, AssignStatementContext, IfStatementContext, FunctionCallContext, CastContext, LiteralContext, SourceFileContext, BlockContext, TimeOpStatementContext, ArrayContext, ParenthesisedContext, FunctionCallExpressionContext, UnaryOpContext, BinaryOpContext, IdentifierContext, LiteralExpressionContext, TupleIndexOpContext, RequireStatementContext, PragmaDirectiveContext, InstantiationContext, NullaryOpContext, UnaryIntrospectionOpContext } from '../grammar/CashScriptParser';
|
|
5
|
-
import { CashScriptVisitor } from '../grammar/CashScriptVisitor';
|
|
1
|
+
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor.js';
|
|
2
|
+
import { ParseTree } from 'antlr4ts/tree/ParseTree.js';
|
|
3
|
+
import { Node, SourceFileNode, ContractNode, ParameterNode, VariableDefinitionNode, FunctionDefinitionNode, AssignNode, IdentifierNode, BranchNode, CastNode, FunctionCallNode, UnaryOpNode, BinaryOpNode, BoolLiteralNode, IntLiteralNode, HexLiteralNode, StringLiteralNode, ExpressionNode, LiteralNode, BlockNode, TimeOpNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, TupleAssignmentNode, NullaryOpNode } from './AST.js';
|
|
4
|
+
import { ContractDefinitionContext, FunctionDefinitionContext, VariableDefinitionContext, TupleAssignmentContext, ParameterContext, AssignStatementContext, IfStatementContext, FunctionCallContext, CastContext, LiteralContext, SourceFileContext, BlockContext, TimeOpStatementContext, ArrayContext, ParenthesisedContext, FunctionCallExpressionContext, UnaryOpContext, BinaryOpContext, IdentifierContext, LiteralExpressionContext, TupleIndexOpContext, RequireStatementContext, PragmaDirectiveContext, InstantiationContext, NullaryOpContext, UnaryIntrospectionOpContext } from '../grammar/CashScriptParser.js';
|
|
5
|
+
import { CashScriptVisitor } from '../grammar/CashScriptVisitor.js';
|
|
6
6
|
export default class AstBuilder extends AbstractParseTreeVisitor<Node> implements CashScriptVisitor<Node> {
|
|
7
7
|
private tree;
|
|
8
8
|
constructor(tree: ParseTree);
|
|
@@ -5,21 +5,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const libauth_1 = require("@bitauth/libauth");
|
|
7
7
|
const utils_1 = require("@cashscript/utils");
|
|
8
|
-
const
|
|
8
|
+
const AbstractParseTreeVisitor_js_1 = require("antlr4ts/tree/AbstractParseTreeVisitor.js");
|
|
9
9
|
const semver_1 = __importDefault(require("semver"));
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
class AstBuilder extends
|
|
10
|
+
const AST_js_1 = require("./AST.js");
|
|
11
|
+
const Location_js_1 = require("./Location.js");
|
|
12
|
+
const Globals_js_1 = require("./Globals.js");
|
|
13
|
+
const Pragma_js_1 = require("./Pragma.js");
|
|
14
|
+
const index_js_1 = require("../index.js");
|
|
15
|
+
const Errors_js_1 = require("../Errors.js");
|
|
16
|
+
class AstBuilder extends AbstractParseTreeVisitor_js_1.AbstractParseTreeVisitor {
|
|
17
17
|
constructor(tree) {
|
|
18
18
|
super();
|
|
19
19
|
this.tree = tree;
|
|
20
20
|
}
|
|
21
21
|
defaultResult() {
|
|
22
|
-
return new
|
|
22
|
+
return new AST_js_1.BoolLiteralNode(false);
|
|
23
23
|
}
|
|
24
24
|
build() {
|
|
25
25
|
return this.visit(this.tree);
|
|
@@ -29,21 +29,21 @@ class AstBuilder extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
29
29
|
this.processPragma(pragma);
|
|
30
30
|
});
|
|
31
31
|
const contract = this.visit(ctx.contractDefinition());
|
|
32
|
-
const sourceFileNode = new
|
|
33
|
-
sourceFileNode.location =
|
|
32
|
+
const sourceFileNode = new AST_js_1.SourceFileNode(contract);
|
|
33
|
+
sourceFileNode.location = Location_js_1.Location.fromCtx(ctx);
|
|
34
34
|
return sourceFileNode;
|
|
35
35
|
}
|
|
36
36
|
processPragma(ctx) {
|
|
37
|
-
const pragmaName =
|
|
38
|
-
if (pragmaName !==
|
|
37
|
+
const pragmaName = (0, Pragma_js_1.getPragmaName)(ctx.pragmaName().text);
|
|
38
|
+
if (pragmaName !== Pragma_js_1.PragmaName.CASHSCRIPT)
|
|
39
39
|
throw new Error(); // Shouldn't happen
|
|
40
40
|
// Strip any -beta tags
|
|
41
|
-
const actualVersion =
|
|
41
|
+
const actualVersion = index_js_1.version.replace(/-.*/g, '');
|
|
42
42
|
ctx.pragmaValue().versionConstraint().forEach((constraint) => {
|
|
43
|
-
const op =
|
|
43
|
+
const op = (0, Pragma_js_1.getVersionOpFromCtx)(constraint.versionOperator());
|
|
44
44
|
const versionConstraint = `${op}${constraint.VersionLiteral().text}`;
|
|
45
45
|
if (!semver_1.default.satisfies(actualVersion, versionConstraint)) {
|
|
46
|
-
throw new
|
|
46
|
+
throw new Errors_js_1.VersionError(actualVersion, versionConstraint);
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -51,152 +51,154 @@ class AstBuilder extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
51
51
|
const name = ctx.Identifier().text;
|
|
52
52
|
const parameters = ctx.parameterList().parameter().map((p) => this.visit(p));
|
|
53
53
|
const functions = ctx.functionDefinition().map((f) => this.visit(f));
|
|
54
|
-
const contract = new
|
|
55
|
-
contract.location =
|
|
54
|
+
const contract = new AST_js_1.ContractNode(name, parameters, functions);
|
|
55
|
+
contract.location = Location_js_1.Location.fromCtx(ctx);
|
|
56
56
|
return contract;
|
|
57
57
|
}
|
|
58
58
|
visitFunctionDefinition(ctx) {
|
|
59
59
|
const name = ctx.Identifier().text;
|
|
60
60
|
const parameters = ctx.parameterList().parameter().map((p) => this.visit(p));
|
|
61
61
|
const statements = ctx.statement().map((s) => this.visit(s));
|
|
62
|
-
const block = new
|
|
63
|
-
block.location =
|
|
64
|
-
const functionDefinition = new
|
|
65
|
-
functionDefinition.location =
|
|
62
|
+
const block = new AST_js_1.BlockNode(statements);
|
|
63
|
+
block.location = Location_js_1.Location.fromCtx(ctx);
|
|
64
|
+
const functionDefinition = new AST_js_1.FunctionDefinitionNode(name, parameters, block);
|
|
65
|
+
functionDefinition.location = Location_js_1.Location.fromCtx(ctx);
|
|
66
66
|
return functionDefinition;
|
|
67
67
|
}
|
|
68
68
|
visitParameter(ctx) {
|
|
69
|
-
const type = utils_1.parseType(ctx.typeName().text);
|
|
69
|
+
const type = (0, utils_1.parseType)(ctx.typeName().text);
|
|
70
70
|
const name = ctx.Identifier().text;
|
|
71
|
-
const parameter = new
|
|
72
|
-
parameter.location =
|
|
71
|
+
const parameter = new AST_js_1.ParameterNode(type, name);
|
|
72
|
+
parameter.location = Location_js_1.Location.fromCtx(ctx);
|
|
73
73
|
return parameter;
|
|
74
74
|
}
|
|
75
75
|
visitVariableDefinition(ctx) {
|
|
76
|
-
|
|
76
|
+
var _a, _b;
|
|
77
|
+
const type = (0, utils_1.parseType)(ctx.typeName().text);
|
|
78
|
+
const modifier = (_b = (_a = ctx.modifier()) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
|
|
77
79
|
const name = ctx.Identifier().text;
|
|
78
80
|
const expression = this.visit(ctx.expression());
|
|
79
|
-
const variableDefinition = new
|
|
80
|
-
variableDefinition.location =
|
|
81
|
+
const variableDefinition = new AST_js_1.VariableDefinitionNode(type, modifier, name, expression);
|
|
82
|
+
variableDefinition.location = Location_js_1.Location.fromCtx(ctx);
|
|
81
83
|
return variableDefinition;
|
|
82
84
|
}
|
|
83
85
|
visitTupleAssignment(ctx) {
|
|
84
86
|
const expression = this.visit(ctx.expression());
|
|
85
87
|
const names = ctx.Identifier();
|
|
86
88
|
const types = ctx.typeName();
|
|
87
|
-
const [var1, var2] = names.map((name, i) => ({ name: name.text, type: utils_1.parseType(types[i].text) }));
|
|
88
|
-
const tupleAssignment = new
|
|
89
|
-
tupleAssignment.location =
|
|
89
|
+
const [var1, var2] = names.map((name, i) => ({ name: name.text, type: (0, utils_1.parseType)(types[i].text) }));
|
|
90
|
+
const tupleAssignment = new AST_js_1.TupleAssignmentNode(var1, var2, expression);
|
|
91
|
+
tupleAssignment.location = Location_js_1.Location.fromCtx(ctx);
|
|
90
92
|
return tupleAssignment;
|
|
91
93
|
}
|
|
92
94
|
visitAssignStatement(ctx) {
|
|
93
|
-
const identifier = new
|
|
94
|
-
identifier.location =
|
|
95
|
+
const identifier = new AST_js_1.IdentifierNode(ctx.Identifier().text);
|
|
96
|
+
identifier.location = Location_js_1.Location.fromToken(ctx.Identifier().symbol);
|
|
95
97
|
const expression = this.visit(ctx.expression());
|
|
96
|
-
const assign = new
|
|
97
|
-
assign.location =
|
|
98
|
+
const assign = new AST_js_1.AssignNode(identifier, expression);
|
|
99
|
+
assign.location = Location_js_1.Location.fromCtx(ctx);
|
|
98
100
|
return assign;
|
|
99
101
|
}
|
|
100
102
|
visitTimeOpStatement(ctx) {
|
|
101
103
|
const expression = this.visit(ctx.expression());
|
|
102
|
-
const timeOp = new
|
|
103
|
-
timeOp.location =
|
|
104
|
+
const timeOp = new AST_js_1.TimeOpNode(ctx.TxVar().text, expression);
|
|
105
|
+
timeOp.location = Location_js_1.Location.fromCtx(ctx);
|
|
104
106
|
return timeOp;
|
|
105
107
|
}
|
|
106
108
|
visitRequireStatement(ctx) {
|
|
107
109
|
const expression = this.visit(ctx.expression());
|
|
108
|
-
const require = new
|
|
109
|
-
require.location =
|
|
110
|
+
const require = new AST_js_1.RequireNode(expression);
|
|
111
|
+
require.location = Location_js_1.Location.fromCtx(ctx);
|
|
110
112
|
return require;
|
|
111
113
|
}
|
|
112
114
|
visitIfStatement(ctx) {
|
|
113
115
|
const condition = this.visit(ctx.expression());
|
|
114
116
|
const ifBlock = this.visit(ctx._ifBlock);
|
|
115
117
|
const elseBlock = ctx._elseBlock && this.visit(ctx._elseBlock);
|
|
116
|
-
const branch = new
|
|
117
|
-
branch.location =
|
|
118
|
+
const branch = new AST_js_1.BranchNode(condition, ifBlock, elseBlock);
|
|
119
|
+
branch.location = Location_js_1.Location.fromCtx(ctx);
|
|
118
120
|
return branch;
|
|
119
121
|
}
|
|
120
122
|
visitBlock(ctx) {
|
|
121
123
|
const statements = ctx.statement().map((s) => this.visit(s));
|
|
122
|
-
const block = new
|
|
123
|
-
block.location =
|
|
124
|
+
const block = new AST_js_1.BlockNode(statements);
|
|
125
|
+
block.location = Location_js_1.Location.fromCtx(ctx);
|
|
124
126
|
return block;
|
|
125
127
|
}
|
|
126
128
|
visitParenthesised(ctx) {
|
|
127
129
|
return this.visit(ctx.expression());
|
|
128
130
|
}
|
|
129
131
|
visitCast(ctx) {
|
|
130
|
-
const type = utils_1.parseType(ctx.typeName().text);
|
|
132
|
+
const type = (0, utils_1.parseType)(ctx.typeName().text);
|
|
131
133
|
const expression = this.visit(ctx._castable);
|
|
132
134
|
const size = ctx._size && this.visit(ctx._size);
|
|
133
|
-
const cast = new
|
|
134
|
-
cast.location =
|
|
135
|
+
const cast = new AST_js_1.CastNode(type, expression, size);
|
|
136
|
+
cast.location = Location_js_1.Location.fromCtx(ctx);
|
|
135
137
|
return cast;
|
|
136
138
|
}
|
|
137
139
|
visitFunctionCallExpression(ctx) {
|
|
138
140
|
return this.visit(ctx.functionCall());
|
|
139
141
|
}
|
|
140
142
|
visitFunctionCall(ctx) {
|
|
141
|
-
const identifier = new
|
|
142
|
-
identifier.location =
|
|
143
|
+
const identifier = new AST_js_1.IdentifierNode(ctx.Identifier().text);
|
|
144
|
+
identifier.location = Location_js_1.Location.fromToken(ctx.Identifier().symbol);
|
|
143
145
|
const parameters = ctx.expressionList().expression().map((e) => this.visit(e));
|
|
144
|
-
const functionCall = new
|
|
145
|
-
functionCall.location =
|
|
146
|
+
const functionCall = new AST_js_1.FunctionCallNode(identifier, parameters);
|
|
147
|
+
functionCall.location = Location_js_1.Location.fromCtx(ctx);
|
|
146
148
|
return functionCall;
|
|
147
149
|
}
|
|
148
150
|
visitInstantiation(ctx) {
|
|
149
|
-
const identifier = new
|
|
150
|
-
identifier.location =
|
|
151
|
+
const identifier = new AST_js_1.IdentifierNode(ctx.Identifier().text);
|
|
152
|
+
identifier.location = Location_js_1.Location.fromToken(ctx.Identifier().symbol);
|
|
151
153
|
const parameters = ctx.expressionList().expression().map((e) => this.visit(e));
|
|
152
|
-
const instantiation = new
|
|
153
|
-
instantiation.location =
|
|
154
|
+
const instantiation = new AST_js_1.InstantiationNode(identifier, parameters);
|
|
155
|
+
instantiation.location = Location_js_1.Location.fromCtx(ctx);
|
|
154
156
|
return instantiation;
|
|
155
157
|
}
|
|
156
158
|
visitTupleIndexOp(ctx) {
|
|
157
159
|
const tuple = this.visit(ctx.expression());
|
|
158
160
|
const index = parseInt(ctx._index.text, 10);
|
|
159
|
-
const tupleIndexOp = new
|
|
160
|
-
tupleIndexOp.location =
|
|
161
|
+
const tupleIndexOp = new AST_js_1.TupleIndexOpNode(tuple, index);
|
|
162
|
+
tupleIndexOp.location = Location_js_1.Location.fromCtx(ctx);
|
|
161
163
|
return tupleIndexOp;
|
|
162
164
|
}
|
|
163
165
|
visitNullaryOp(ctx) {
|
|
164
166
|
const operator = ctx.text;
|
|
165
|
-
const nullaryOp = new
|
|
166
|
-
nullaryOp.location =
|
|
167
|
+
const nullaryOp = new AST_js_1.NullaryOpNode(operator);
|
|
168
|
+
nullaryOp.location = Location_js_1.Location.fromCtx(ctx);
|
|
167
169
|
return nullaryOp;
|
|
168
170
|
}
|
|
169
171
|
visitUnaryIntrospectionOp(ctx) {
|
|
170
172
|
const operator = `${ctx._scope.text}[i]${ctx._op.text}`;
|
|
171
173
|
const expression = this.visit(ctx.expression());
|
|
172
|
-
const unaryOp = new
|
|
173
|
-
unaryOp.location =
|
|
174
|
+
const unaryOp = new AST_js_1.UnaryOpNode(operator, expression);
|
|
175
|
+
unaryOp.location = Location_js_1.Location.fromCtx(ctx);
|
|
174
176
|
return unaryOp;
|
|
175
177
|
}
|
|
176
178
|
visitUnaryOp(ctx) {
|
|
177
179
|
const operator = ctx._op.text;
|
|
178
180
|
const expression = this.visit(ctx.expression());
|
|
179
|
-
const unaryOp = new
|
|
180
|
-
unaryOp.location =
|
|
181
|
+
const unaryOp = new AST_js_1.UnaryOpNode(operator, expression);
|
|
182
|
+
unaryOp.location = Location_js_1.Location.fromCtx(ctx);
|
|
181
183
|
return unaryOp;
|
|
182
184
|
}
|
|
183
185
|
visitBinaryOp(ctx) {
|
|
184
186
|
const left = this.visit(ctx._left);
|
|
185
187
|
const operator = ctx._op.text;
|
|
186
188
|
const right = this.visit(ctx._right);
|
|
187
|
-
const binaryOp = new
|
|
188
|
-
binaryOp.location =
|
|
189
|
+
const binaryOp = new AST_js_1.BinaryOpNode(left, operator, right);
|
|
190
|
+
binaryOp.location = Location_js_1.Location.fromCtx(ctx);
|
|
189
191
|
return binaryOp;
|
|
190
192
|
}
|
|
191
193
|
visitArray(ctx) {
|
|
192
194
|
const elements = ctx.expression().map((e) => this.visit(e));
|
|
193
|
-
const array = new
|
|
194
|
-
array.location =
|
|
195
|
+
const array = new AST_js_1.ArrayNode(elements);
|
|
196
|
+
array.location = Location_js_1.Location.fromCtx(ctx);
|
|
195
197
|
return array;
|
|
196
198
|
}
|
|
197
199
|
visitIdentifier(ctx) {
|
|
198
|
-
const identifier = new
|
|
199
|
-
identifier.location =
|
|
200
|
+
const identifier = new AST_js_1.IdentifierNode(ctx.Identifier().text);
|
|
201
|
+
identifier.location = Location_js_1.Location.fromCtx(ctx);
|
|
200
202
|
return identifier;
|
|
201
203
|
}
|
|
202
204
|
visitLiteralExpression(ctx) {
|
|
@@ -223,8 +225,8 @@ class AstBuilder extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
223
225
|
createBooleanLiteral(ctx) {
|
|
224
226
|
const boolString = ctx.BooleanLiteral().text;
|
|
225
227
|
const boolValue = boolString === 'true';
|
|
226
|
-
const booleanLiteral = new
|
|
227
|
-
booleanLiteral.location =
|
|
228
|
+
const booleanLiteral = new AST_js_1.BoolLiteralNode(boolValue);
|
|
229
|
+
booleanLiteral.location = Location_js_1.Location.fromCtx(ctx);
|
|
228
230
|
return booleanLiteral;
|
|
229
231
|
}
|
|
230
232
|
createIntLiteral(ctx) {
|
|
@@ -232,38 +234,38 @@ class AstBuilder extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
232
234
|
const numberString = numberCtx.NumberLiteral().text;
|
|
233
235
|
const numberUnit = numberCtx.NumberUnit();
|
|
234
236
|
let numberValue = parseInt(numberString, 10);
|
|
235
|
-
numberValue *= numberUnit ?
|
|
236
|
-
const intLiteral = new
|
|
237
|
-
intLiteral.location =
|
|
237
|
+
numberValue *= numberUnit ? Globals_js_1.NumberUnit[numberUnit.text.toUpperCase()] : 1;
|
|
238
|
+
const intLiteral = new AST_js_1.IntLiteralNode(numberValue);
|
|
239
|
+
intLiteral.location = Location_js_1.Location.fromCtx(ctx);
|
|
238
240
|
return intLiteral;
|
|
239
241
|
}
|
|
240
242
|
createStringLiteral(ctx) {
|
|
241
243
|
const rawString = ctx.StringLiteral().text;
|
|
242
244
|
const stringValue = rawString.substring(1, rawString.length - 1);
|
|
243
245
|
const quote = rawString.substring(0, 1);
|
|
244
|
-
const stringLiteral = new
|
|
245
|
-
stringLiteral.location =
|
|
246
|
+
const stringLiteral = new AST_js_1.StringLiteralNode(stringValue, quote);
|
|
247
|
+
stringLiteral.location = Location_js_1.Location.fromCtx(ctx);
|
|
246
248
|
return stringLiteral;
|
|
247
249
|
}
|
|
248
250
|
createDateLiteral(ctx) {
|
|
249
251
|
const rawString = ctx.DateLiteral().text;
|
|
250
252
|
const stringValue = rawString.substring(6, rawString.length - 2).trim();
|
|
251
253
|
if (!/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/.test(stringValue)) {
|
|
252
|
-
throw new
|
|
254
|
+
throw new Errors_js_1.ParseError('Date should be in format `YYYY-MM-DDThh:mm:ss`', Location_js_1.Location.fromCtx(ctx));
|
|
253
255
|
}
|
|
254
256
|
const timestamp = Math.round(Date.parse(stringValue) / 1000);
|
|
255
257
|
if (Number.isNaN(timestamp)) {
|
|
256
|
-
throw new
|
|
258
|
+
throw new Errors_js_1.ParseError(`Incorrectly formatted date "${stringValue}"`, Location_js_1.Location.fromCtx(ctx));
|
|
257
259
|
}
|
|
258
|
-
const intLiteral = new
|
|
259
|
-
intLiteral.location =
|
|
260
|
+
const intLiteral = new AST_js_1.IntLiteralNode(timestamp);
|
|
261
|
+
intLiteral.location = Location_js_1.Location.fromCtx(ctx);
|
|
260
262
|
return intLiteral;
|
|
261
263
|
}
|
|
262
264
|
createHexLiteral(ctx) {
|
|
263
265
|
const hexString = ctx.HexLiteral().text;
|
|
264
|
-
const hexValue = libauth_1.hexToBin(hexString.substring(2));
|
|
265
|
-
const hexLiteral = new
|
|
266
|
-
hexLiteral.location =
|
|
266
|
+
const hexValue = (0, libauth_1.hexToBin)(hexString.substring(2));
|
|
267
|
+
const hexLiteral = new AST_js_1.HexLiteralNode(hexValue);
|
|
268
|
+
hexLiteral.location = Location_js_1.Location.fromCtx(ctx);
|
|
267
269
|
return hexLiteral;
|
|
268
270
|
}
|
|
269
271
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Node, SourceFileNode, ContractNode, ParameterNode, VariableDefinitionNode, FunctionDefinitionNode, AssignNode, IdentifierNode, BranchNode, CastNode, FunctionCallNode, UnaryOpNode, BinaryOpNode, BoolLiteralNode, IntLiteralNode, HexLiteralNode, StringLiteralNode, BlockNode, TimeOpNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, TupleAssignmentNode, NullaryOpNode } from './AST';
|
|
2
|
-
import AstVisitor from './AstVisitor';
|
|
1
|
+
import { Node, SourceFileNode, ContractNode, ParameterNode, VariableDefinitionNode, FunctionDefinitionNode, AssignNode, IdentifierNode, BranchNode, CastNode, FunctionCallNode, UnaryOpNode, BinaryOpNode, BoolLiteralNode, IntLiteralNode, HexLiteralNode, StringLiteralNode, BlockNode, TimeOpNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, TupleAssignmentNode, NullaryOpNode } from './AST.js';
|
|
2
|
+
import AstVisitor from './AstVisitor.js';
|
|
3
3
|
export default class AstTraversal extends AstVisitor<Node> {
|
|
4
4
|
visitSourceFile(node: SourceFileNode): Node;
|
|
5
5
|
visitContract(node: ContractNode): Node;
|
|
@@ -3,8 +3,8 @@ 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
|
-
const
|
|
7
|
-
class AstTraversal extends
|
|
6
|
+
const AstVisitor_js_1 = __importDefault(require("./AstVisitor.js"));
|
|
7
|
+
class AstTraversal extends AstVisitor_js_1.default {
|
|
8
8
|
visitSourceFile(node) {
|
|
9
9
|
node.contract = this.visit(node.contract);
|
|
10
10
|
return node;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node, SourceFileNode, ContractNode, ParameterNode, VariableDefinitionNode, FunctionDefinitionNode, AssignNode, IdentifierNode, BranchNode, CastNode, FunctionCallNode, UnaryOpNode, BinaryOpNode, BoolLiteralNode, IntLiteralNode, HexLiteralNode, StringLiteralNode, BlockNode, TimeOpNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, TupleAssignmentNode, NullaryOpNode } from './AST';
|
|
1
|
+
import { Node, SourceFileNode, ContractNode, ParameterNode, VariableDefinitionNode, FunctionDefinitionNode, AssignNode, IdentifierNode, BranchNode, CastNode, FunctionCallNode, UnaryOpNode, BinaryOpNode, BoolLiteralNode, IntLiteralNode, HexLiteralNode, StringLiteralNode, BlockNode, TimeOpNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, TupleAssignmentNode, NullaryOpNode } from './AST.js';
|
|
2
2
|
export default abstract class AstVisitor<T> {
|
|
3
3
|
abstract visitSourceFile(node: SourceFileNode): T;
|
|
4
4
|
abstract visitContract(node: ContractNode): T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SymbolTable } from './SymbolTable';
|
|
1
|
+
import { SymbolTable } from './SymbolTable.js';
|
|
2
2
|
export declare const NumberUnit: {
|
|
3
3
|
[index: string]: number;
|
|
4
4
|
};
|
|
@@ -25,4 +25,7 @@ export declare enum Class {
|
|
|
25
25
|
LOCKING_BYTECODE_P2PKH = "LockingBytecodeP2PKH",
|
|
26
26
|
LOCKING_BYTECODE_NULLDATA = "LockingBytecodeNullData"
|
|
27
27
|
}
|
|
28
|
+
export declare enum Modifier {
|
|
29
|
+
CONSTANT = "constant"
|
|
30
|
+
}
|
|
28
31
|
export declare const GLOBAL_SYMBOL_TABLE: SymbolTable;
|