Skip to content

Commit

Permalink
Merge pull request #33 from ConsenSys/support-solidity-084
Browse files Browse the repository at this point in the history
Support for Solidity 0.8.4
  • Loading branch information
cd1m0 authored Apr 30, 2021
2 parents 2217b8b + 821fcf0 commit 09d9365
Show file tree
Hide file tree
Showing 30 changed files with 15,093 additions and 2,153 deletions.
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
11,232 changes: 11,157 additions & 75 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,31 @@
"solc-0.8.1": "npm:[email protected]",
"solc-0.8.2": "npm:[email protected]",
"solc-0.8.3": "npm:[email protected]",
"solc-0.8.4": "npm:[email protected]",
"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",
"pegjs": "^0.10.0",
"prettier": "2.2.1",
"ts-node": "^9.1.1",
"typedoc": "^0.20.34",
"typescript": "^4.2.3",
"pegjs": "^0.10.0",
"ts-pegjs": "^0.3.1"
"ts-pegjs": "^0.3.1",
"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
14 changes: 12 additions & 2 deletions src/ast/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ASTNode } from "./ast_node";
import { StateVariableVisibility } from "./constants";
import { EnumDefinition, StructDefinition } from "./implementation/declaration";
import { ContractDefinition } from "./implementation/declaration/contract_definition";
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 All @@ -24,6 +25,7 @@ export type AnyResolvable =
| VariableDeclaration
| FunctionDefinition
| ModifierDefinition
| ErrorDefinition
| EventDefinition
| StructDefinition
| EnumDefinition
Expand Down Expand Up @@ -139,7 +141,8 @@ function* lookupInSourceUnit(name: string, scope: SourceUnit): Iterable<AnyResol
child instanceof FunctionDefinition ||
child instanceof ContractDefinition ||
child instanceof StructDefinition ||
child instanceof EnumDefinition) &&
child instanceof EnumDefinition ||
child instanceof ErrorDefinition) &&
child.name === name
) {
yield child;
Expand All @@ -159,6 +162,7 @@ function* lookupInSourceUnit(name: string, scope: SourceUnit): Iterable<AnyResol
// `import {<name>} from "..."` or `import {a as <name>} from "..."`
for (const [foreignDef, alias] of child.vSymbolAliases) {
let symImportName: string;

const originalDef =
foreignDef instanceof ImportDirective ? foreignDef.vSourceUnit : foreignDef;

Expand All @@ -167,6 +171,7 @@ function* lookupInSourceUnit(name: string, scope: SourceUnit): Iterable<AnyResol
} else {
if (foreignDef instanceof ImportDirective) {
symImportName = foreignDef.unitAlias;

if (symImportName === "") {
throw new Error(
`Unexpected ImportDirective foreign def with non-unit alias ${pp(
Expand Down Expand Up @@ -204,10 +209,12 @@ function* lookupInContractDefinition(
child instanceof ModifierDefinition ||
child instanceof EventDefinition ||
child instanceof StructDefinition ||
child instanceof EnumDefinition) &&
child instanceof EnumDefinition ||
child instanceof ErrorDefinition) &&
child.name === name
) {
let sigHash: string | undefined;

if (child instanceof FunctionDefinition) {
sigHash = child.canonicalSignatureHash;
} else if (
Expand Down Expand Up @@ -272,6 +279,7 @@ function* lookupInBlock(name: string, scope: Block | UncheckedBlock): Iterable<A
*/
function lookupInScope(name: string, scope: ScopeNode): Set<AnyResolvable> {
let results: Iterable<AnyResolvable>;

if (scope instanceof SourceUnit) {
results = lookupInSourceUnit(name, scope);
} else if (scope instanceof ContractDefinition) {
Expand Down Expand Up @@ -323,13 +331,15 @@ export function resolveAny(

for (let i = 0; i < elements.length; i++) {
const element = elements[i];

let res: Set<AnyResolvable> | undefined;

if (i == 0) {
// If this is the first element (e.g. `A` in `A.B.C`), walk up the
// stack of scopes starting from the current context, looking for `A`
while (scope !== undefined) {
res = lookupInScope(element, scope);

if (res.size > 0) {
// Sanity check - when multiple results are found, they must either be overloaded events
// or overloaded functions/public state vars.
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
63 changes: 63 additions & 0 deletions src/ast/implementation/declaration/error_definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ASTNode } from "../../ast_node";
import { SourceUnit } from "../meta";
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` for compatibility reasons (for and instance, during node creation).
* - Is instance of `StructuredDocumentation` in other cases.
*/
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 a scoped `ContractDefinition` if event is declared in contract.
* Reference to a scoped `SourceUnit` if event is declared on file level.
*/
get vScope(): ContractDefinition | SourceUnit {
return this.parent as ContractDefinition | SourceUnit;
}
}
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
Loading

0 comments on commit 09d9365

Please sign in to comment.