Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Solidity 0.8.4 #33

Merged
merged 5 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NODE_LIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ElementaryTypeNameExpression
EmitStatement
EnumDefinition
EnumValue
ErrorDefinition
EventDefinition
ExpressionStatement
ForStatement
Expand All @@ -43,6 +44,7 @@ ParameterList
PlaceholderStatement
PragmaDirective
Return
RevertStatement
SourceUnit
StructDefinition
StructuredDocumentation
Expand Down
549 changes: 387 additions & 162 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,29 @@
"solc-0.8.1": "npm:solc-0.8.1-fixed@0.8.1",
"solc-0.8.2": "npm:solc@0.8.2",
"solc-0.8.3": "npm:solc@0.8.3",
"solc-0.8.4": "npm:solc@0.8.4",
"src-location": "^1.1.0",
"web3-eth-abi": "^1.3.4"
"web3-eth-abi": "^1.3.5"
},
"devDependencies": {
"@types/fs-extra": "^9.0.9",
"@types/fs-extra": "^9.0.11",
"@types/minimist": "^1.2.1",
"@types/mocha": "^8.2.2",
"@types/node": "^12.20.7",
"@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"@types/node": "^12.20.10",
"@types/semver": "^7.3.5",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"codecov": "^3.8.1",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"expect": "^26.6.2",
"mocha": "^8.3.2",
"nyc": "^15.1.0",
"prettier": "2.2.1",
"ts-node": "^9.1.1",
"typedoc": "^0.20.34",
"typescript": "^4.2.3"
"typedoc": "^0.20.36",
"typescript": "^4.2.4"
},
"homepage": "https://consensys.github.io/solc-typed-ast",
"bugs": "https://github.com/ConsenSys/solc-typed-ast/issues",
Expand Down
37 changes: 36 additions & 1 deletion src/ast/ast_node_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FunctionStateMutability, FunctionVisibility } from "./constants";
import { ContractDefinition } from "./implementation/declaration/contract_definition";
import { EnumDefinition } from "./implementation/declaration/enum_definition";
import { EnumValue } from "./implementation/declaration/enum_value";
import { ErrorDefinition } from "./implementation/declaration/error_definition";
import { EventDefinition } from "./implementation/declaration/event_definition";
import { FunctionDefinition } from "./implementation/declaration/function_definition";
import { ModifierDefinition } from "./implementation/declaration/modifier_definition";
Expand Down Expand Up @@ -46,6 +47,7 @@ import { IfStatement } from "./implementation/statement/if_statement";
import { InlineAssembly } from "./implementation/statement/inline_assembly";
import { PlaceholderStatement } from "./implementation/statement/placeholder_statement";
import { Return } from "./implementation/statement/return";
import { RevertStatement } from "./implementation/statement/revert_statement";
import { Statement } from "./implementation/statement/statement";
import { Throw } from "./implementation/statement/throw";
import { TryCatchClause } from "./implementation/statement/try_catch_clause";
Expand Down Expand Up @@ -96,6 +98,7 @@ const argExtractionMapping = new Map<ASTNodeConstructor<ASTNode>, (node: any) =>
node.abstract,
node.fullyImplemented,
node.linearizedBaseContracts,
node.usedErrors,
node.documentation,
node.children,
node.nameLocation,
Expand All @@ -120,6 +123,16 @@ const argExtractionMapping = new Map<ASTNodeConstructor<ASTNode>, (node: any) =>
node.raw
]
],
[
ErrorDefinition,
(node: ErrorDefinition): Specific<ConstructorParameters<typeof ErrorDefinition>> => [
node.name,
node.vParameters,
node.documentation,
node.nameLocation,
node.raw
]
],
[
EventDefinition,
(node: EventDefinition): Specific<ConstructorParameters<typeof EventDefinition>> => [
Expand Down Expand Up @@ -535,6 +548,14 @@ const argExtractionMapping = new Map<ASTNodeConstructor<ASTNode>, (node: any) =>
node.raw
]
],
[
RevertStatement,
(node: RevertStatement): Specific<ConstructorParameters<typeof RevertStatement>> => [
node.errorCall,
node.documentation,
node.raw
]
],
[
Statement,
(node: Statement): Specific<ConstructorParameters<typeof Statement>> => [
Expand Down Expand Up @@ -677,6 +698,12 @@ export class ASTNodeFactory {
return this.make(EnumValue, ...args);
}

makeErrorDefinition(
...args: Specific<ConstructorParameters<typeof ErrorDefinition>>
): ErrorDefinition {
return this.make(ErrorDefinition, ...args);
}

makeEventDefinition(
...args: Specific<ConstructorParameters<typeof EventDefinition>>
): EventDefinition {
Expand Down Expand Up @@ -905,6 +932,12 @@ export class ASTNodeFactory {
return this.make(Return, ...args);
}

makeRevertStatement(
...args: Specific<ConstructorParameters<typeof RevertStatement>>
): RevertStatement {
return this.make(RevertStatement, ...args);
}

makeStatement(...args: Specific<ConstructorParameters<typeof Statement>>): Statement {
return this.make(Statement, ...args);
}
Expand Down Expand Up @@ -977,6 +1010,7 @@ export class ASTNodeFactory {
| ContractDefinition
| FunctionDefinition
| StructDefinition
| ErrorDefinition
| EventDefinition
| EnumDefinition
| ImportDirective
Expand Down Expand Up @@ -1007,7 +1041,7 @@ export class ASTNodeFactory {
typeString = result.join(" ");
} else if (target instanceof ContractDefinition) {
typeString = `type(contract ${target.name})`;
} else if (target instanceof EventDefinition) {
} else if (target instanceof EventDefinition || target instanceof ErrorDefinition) {
const args = target.vParameters.vParameters.map(this.typeExtractor);

typeString = `function (${args.join(",")})`;
Expand Down Expand Up @@ -1092,6 +1126,7 @@ export class ASTNodeFactory {

if (node instanceof ContractDefinition) {
node.linearizedBaseContracts = node.linearizedBaseContracts.map(patch);
node.usedErrors = node.usedErrors.map(patch);
}

if (
Expand Down
26 changes: 26 additions & 0 deletions src/ast/implementation/declaration/contract_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SourceUnit } from "../meta/source_unit";
import { StructuredDocumentation } from "../meta/structured_documentation";
import { UsingForDirective } from "../meta/using_for_directive";
import { EnumDefinition } from "./enum_definition";
import { ErrorDefinition } from "./error_definition";
import { EventDefinition } from "./event_definition";
import { FunctionDefinition } from "./function_definition";
import { ModifierDefinition } from "./modifier_definition";
Expand Down Expand Up @@ -54,6 +55,11 @@ export class ContractDefinition extends ASTNodeWithChildren<ASTNode> {
*/
linearizedBaseContracts: number[];

/**
* Used error definition ids (including external definition ids)
*/
usedErrors: number[];

constructor(
id: number,
src: string,
Expand All @@ -64,6 +70,7 @@ export class ContractDefinition extends ASTNodeWithChildren<ASTNode> {
abstract: boolean,
fullyImplemented: boolean,
linearizedBaseContracts: number[],
usedErrors: number[],
documentation?: string | StructuredDocumentation,
children?: Iterable<ASTNode>,
nameLocation?: string,
Expand All @@ -77,6 +84,7 @@ export class ContractDefinition extends ASTNodeWithChildren<ASTNode> {
this.abstract = abstract;
this.fullyImplemented = fullyImplemented;
this.linearizedBaseContracts = linearizedBaseContracts;
this.usedErrors = usedErrors;

if (children) {
for (const node of children) {
Expand Down Expand Up @@ -150,6 +158,15 @@ export class ContractDefinition extends ASTNodeWithChildren<ASTNode> {
return this.linearizedBaseContracts.map((id) => context.locate(id)) as ContractDefinition[];
}

/**
* Used error definitions (including external definitions)
*/
get vUsedErrors(): readonly ErrorDefinition[] {
const context = this.requiredContext;

return this.usedErrors.map((id) => context.locate(id)) as ErrorDefinition[];
}

/**
* Inheritance specifiers
*/
Expand Down Expand Up @@ -188,6 +205,15 @@ export class ContractDefinition extends ASTNodeWithChildren<ASTNode> {
) as EventDefinition[];
}

/**
* Errors of the contract
*/
get vErrors(): readonly ErrorDefinition[] {
return this.ownChildren.filter(
(node) => node instanceof ErrorDefinition
) as ErrorDefinition[];
}

/**
* Functions of the contract
*/
Expand Down
61 changes: 61 additions & 0 deletions src/ast/implementation/declaration/error_definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { ASTNode } from "../../ast_node";
import { ParameterList } from "../meta/parameter_list";
import { StructuredDocumentation } from "../meta/structured_documentation";
import { ContractDefinition } from "./contract_definition";

export class ErrorDefinition extends ASTNode {
/**
* The name of the error
*/
name: string;

/**
* The source range for name string
*/
nameLocation?: string;

/**
* Optional documentation appearing above the error definition:
* - Is `undefined` when not specified.
* - Is type of `string` when specified and compiler version is older than `0.6.3`.
* - Is instance of `StructuredDocumentation` when specified and compiler version is `0.6.3` or newer.
*/
documentation?: string | StructuredDocumentation;

/**
* A list of values that is passed on to the EVM logging facility
*/
vParameters: ParameterList;

constructor(
id: number,
src: string,
type: string,
name: string,
parameters: ParameterList,
documentation?: string | StructuredDocumentation,
nameLocation?: string,
raw?: any
) {
super(id, src, type, raw);

this.name = name;
this.documentation = documentation;
this.nameLocation = nameLocation;

this.vParameters = parameters;

this.acceptChildren();
}

get children(): readonly ASTNode[] {
return this.pickNodes(this.documentation, this.vParameters);
}

/**
* Reference to its scoped contract
*/
get vScope(): ContractDefinition {
return this.parent as ContractDefinition;
}
}
1 change: 1 addition & 0 deletions src/ast/implementation/declaration/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./contract_definition";
export * from "./enum_definition";
export * from "./enum_value";
export * from "./error_definition";
export * from "./event_definition";
export * from "./function_definition";
export * from "./modifier_definition";
Expand Down
11 changes: 11 additions & 0 deletions src/ast/implementation/meta/source_unit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ASTNode, ASTNodeWithChildren } from "../../ast_node";
import { ContractDefinition } from "../declaration/contract_definition";
import { EnumDefinition } from "../declaration/enum_definition";
import { ErrorDefinition } from "../declaration/error_definition";
import { FunctionDefinition } from "../declaration/function_definition";
import { StructDefinition } from "../declaration/struct_definition";
import { VariableDeclaration } from "../declaration/variable_declaration";
Expand All @@ -11,6 +12,7 @@ export type ExportedSymbol =
| ContractDefinition
| StructDefinition
| EnumDefinition
| ErrorDefinition
| FunctionDefinition
| VariableDeclaration
| ImportDirective;
Expand Down Expand Up @@ -97,6 +99,15 @@ export class SourceUnit extends ASTNodeWithChildren<ASTNode> {
) as EnumDefinition[];
}

/**
* References to file-level error definitions
*/
get vErrors(): readonly ErrorDefinition[] {
return this.ownChildren.filter(
(node) => node instanceof ErrorDefinition
) as ErrorDefinition[];
}

/**
* References to file-level struct definitions
*/
Expand Down
1 change: 1 addition & 0 deletions src/ast/implementation/statement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from "./if_statement";
export * from "./inline_assembly";
export * from "./placeholder_statement";
export * from "./return";
export * from "./revert_statement";
export * from "./statement";
export * from "./throw";
export * from "./try_catch_clause";
Expand Down
29 changes: 29 additions & 0 deletions src/ast/implementation/statement/revert_statement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ASTNode } from "../../ast_node";
import { FunctionCall } from "../expression/function_call";
import { Statement } from "./statement";

export class RevertStatement extends Statement {
/**
* A function call to the error definition
*/
errorCall: FunctionCall;

constructor(
id: number,
src: string,
type: string,
errorCall: FunctionCall,
documentation?: string,
raw?: any
) {
super(id, src, type, documentation, raw);

this.errorCall = errorCall;

this.acceptChildren();
}

get children(): readonly ASTNode[] {
return this.pickNodes(this.errorCall);
}
}
1 change: 1 addition & 0 deletions src/ast/legacy/contract_definition_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class LegacyContractDefinitionProcessor extends LegacyNodeProcessor<Contr
abstract,
fullyImplemented,
linearizedBaseContracts,
[],
documentation,
children,
undefined,
Expand Down
Loading