Skip to content

Commit

Permalink
Merge pull request #76 from ConsenSys/support-solidity-088-089
Browse files Browse the repository at this point in the history
Support for Solidity 0.8.8, 0.8.9 and 0.8.10
  • Loading branch information
blitz-1306 authored Nov 11, 2021
2 parents 7d40fc9 + f10c1d7 commit 013c0d7
Show file tree
Hide file tree
Showing 34 changed files with 7,449 additions and 3,488 deletions.
1 change: 1 addition & 0 deletions NODE_LIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ TupleExpression
UnaryOperation
UncheckedBlock
UserDefinedTypeName
UserDefinedValueTypeDefinition
UsingForDirective
VariableDeclaration
VariableDeclarationStatement
Expand Down
1,469 changes: 827 additions & 642 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 19 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"prepare": "npm run build"
},
"dependencies": {
"findup-sync": "^4.0.0",
"findup-sync": "^5.0.0",
"fs-extra": "^10.0.0",
"jsel": "^1.1.6",
"minimist": "^1.2.5",
Expand Down Expand Up @@ -91,30 +91,33 @@
"solc-0.8.5": "npm:[email protected]",
"solc-0.8.6": "npm:[email protected]",
"solc-0.8.7": "npm:[email protected]",
"solc-0.8.8": "npm:[email protected]",
"solc-0.8.9": "npm:[email protected]",
"solc-0.8.10": "npm:[email protected]",
"src-location": "^1.1.0",
"web3-eth-abi": "^1.5.2"
"web3-eth-abi": "^1.6.0"
},
"devDependencies": {
"@types/fs-extra": "^9.0.12",
"@types/fs-extra": "^9.0.13",
"@types/minimist": "^1.2.2",
"@types/mocha": "^9.0.0",
"@types/node": "^12.20.20",
"@types/semver": "^7.3.8",
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"@types/node": "^12.20.37",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.3.1",
"@typescript-eslint/parser": "^5.3.1",
"codecov": "^3.8.3",
"eslint": "^7.32.0",
"eslint": "^8.2.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"expect": "^27.0.6",
"mocha": "^9.1.0",
"eslint-plugin-prettier": "^4.0.0",
"expect": "^27.3.1",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"peggy": "^1.2.0",
"prettier": "2.3.2",
"ts-node": "^10.2.1",
"ts-pegjs": "^1.1.1",
"typedoc": "^0.21.6",
"typescript": "^4.3.5"
"prettier": "2.4.1",
"ts-node": "^10.4.0",
"ts-pegjs": "^1.2.1",
"typedoc": "^0.22.8",
"typescript": "^4.4.4"
},
"homepage": "https://consensys.github.io/solc-typed-ast",
"bugs": "https://github.com/ConsenSys/solc-typed-ast/issues",
Expand Down
19 changes: 19 additions & 0 deletions src/ast/ast_node_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EventDefinition } from "./implementation/declaration/event_definition";
import { FunctionDefinition } from "./implementation/declaration/function_definition";
import { ModifierDefinition } from "./implementation/declaration/modifier_definition";
import { StructDefinition } from "./implementation/declaration/struct_definition";
import { UserDefinedValueTypeDefinition } from "./implementation/declaration/user_defined_value_type_definition";
import { VariableDeclaration } from "./implementation/declaration/variable_declaration";
import { Assignment } from "./implementation/expression/assignment";
import { BinaryOperation } from "./implementation/expression/binary_operation";
Expand Down Expand Up @@ -190,6 +191,18 @@ const argExtractionMapping = new Map<ASTNodeConstructor<ASTNode>, (node: any) =>
node.raw
]
],
[
UserDefinedValueTypeDefinition,
(
node: UserDefinedValueTypeDefinition
): Specific<ConstructorParameters<typeof UserDefinedValueTypeDefinition>> => [
node.name,
node.canonicalName,
node.underlyingType,
node.nameLocation,
node.raw
]
],
[
VariableDeclaration,
(
Expand Down Expand Up @@ -728,6 +741,12 @@ export class ASTNodeFactory {
return this.make(StructDefinition, ...args);
}

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

makeVariableDeclaration(
...args: Specific<ConstructorParameters<typeof VariableDeclaration>>
): VariableDeclaration {
Expand Down
12 changes: 9 additions & 3 deletions src/ast/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { forAll, pp } from "../misc";
import { ABIEncoderVersion } from "../types/abi";
import { ASTNode } from "./ast_node";
import { StateVariableVisibility } from "./constants";
import { EnumDefinition, StructDefinition } from "./implementation/declaration";
import { ContractDefinition } from "./implementation/declaration/contract_definition";
import { EnumDefinition } from "./implementation/declaration/enum_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";
import { StructDefinition } from "./implementation/declaration/struct_definition";
import { UserDefinedValueTypeDefinition } from "./implementation/declaration/user_defined_value_type_definition";
import { VariableDeclaration } from "./implementation/declaration/variable_declaration";
import { ImportDirective, SourceUnit } from "./implementation/meta";
import {
Expand All @@ -31,6 +33,7 @@ export type AnyResolvable =
| StructDefinition
| EnumDefinition
| ContractDefinition
| UserDefinedValueTypeDefinition
| ImportDirective;

/**
Expand Down Expand Up @@ -152,7 +155,8 @@ function* lookupInSourceUnit(
child instanceof ContractDefinition ||
child instanceof StructDefinition ||
child instanceof EnumDefinition ||
child instanceof ErrorDefinition) &&
child instanceof ErrorDefinition ||
child instanceof UserDefinedValueTypeDefinition) &&
child.name === name
) {
yield child;
Expand Down Expand Up @@ -206,6 +210,7 @@ function* lookupInContractDefinition(
scope: ContractDefinition
): Iterable<AnyResolvable> {
const overridenSigHashes = new Set<string>();

for (const base of scope.vLinearizedBaseContracts) {
for (const child of base.children) {
if (
Expand All @@ -215,7 +220,8 @@ function* lookupInContractDefinition(
child instanceof EventDefinition ||
child instanceof StructDefinition ||
child instanceof EnumDefinition ||
child instanceof ErrorDefinition) &&
child instanceof ErrorDefinition ||
child instanceof UserDefinedValueTypeDefinition) &&
child.name === name
) {
let sigHash: string | undefined;
Expand Down
10 changes: 10 additions & 0 deletions src/ast/implementation/declaration/contract_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EventDefinition } from "./event_definition";
import { FunctionDefinition } from "./function_definition";
import { ModifierDefinition } from "./modifier_definition";
import { StructDefinition } from "./struct_definition";
import { UserDefinedValueTypeDefinition } from "./user_defined_value_type_definition";
import { VariableDeclaration } from "./variable_declaration";

export class ContractDefinition extends ASTNodeWithChildren<ASTNode> {
Expand Down Expand Up @@ -251,6 +252,15 @@ export class ContractDefinition extends ASTNodeWithChildren<ASTNode> {
) as EnumDefinition[];
}

/**
* User-defined value type definitions of contract
*/
get vUserDefinedValueTypes(): readonly UserDefinedValueTypeDefinition[] {
return this.ownChildren.filter(
(node) => node instanceof UserDefinedValueTypeDefinition
) as UserDefinedValueTypeDefinition[];
}

/**
* Constructor reference (if definition is present for this contract)
*/
Expand Down
1 change: 1 addition & 0 deletions src/ast/implementation/declaration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * from "./event_definition";
export * from "./function_definition";
export * from "./modifier_definition";
export * from "./struct_definition";
export * from "./user_defined_value_type_definition";
export * from "./variable_declaration";
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ASTNode } from "../../ast_node";
import { SourceUnit } from "../meta/source_unit";
import { ElementaryTypeName } from "../type/elementary_type_name";
import { ContractDefinition } from "./contract_definition";

export class UserDefinedValueTypeDefinition extends ASTNode {
/**
* The name of the user-defined value type definition
*/
name: string;

/**
* Canonical name (or qualified name), e.g. `DefiningContract.SomeType`.
* Is `undefined` for Solidity 0.8.8. Available since Solidity 0.8.9.
*/
canonicalName?: string;

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

/**
* Aliased value type
*/
underlyingType: ElementaryTypeName;

constructor(
id: number,
src: string,
type: string,
name: string,
canonicalName: string | undefined,
underlyingType: ElementaryTypeName,
nameLocation?: string,
raw?: any
) {
super(id, src, type, raw);

this.name = name;
this.canonicalName = canonicalName;
this.underlyingType = underlyingType;
this.nameLocation = nameLocation;

this.acceptChildren();
}

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

/**
* Reference to its scoped contract or source unit
*/
get vScope(): ContractDefinition | SourceUnit {
return this.parent as ContractDefinition | SourceUnit;
}
}
1 change: 1 addition & 0 deletions src/ast/implementation/declaration/variable_declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class VariableDeclaration extends ASTNode {
canonicalSignatureType(encoderVersion: ABIEncoderVersion): string {
const type = variableDeclarationToTypeNode(this);
const abiType = toABIEncodedType(type, encoderVersion);

return abiTypeToCanonicalName(generalizeType(abiType)[0]);
}

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
Expand Up @@ -4,6 +4,7 @@ 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 { UserDefinedValueTypeDefinition } from "../declaration/user_defined_value_type_definition";
import { VariableDeclaration } from "../declaration/variable_declaration";
import { ImportDirective } from "./import_directive";
import { PragmaDirective } from "./pragma_directive";
Expand All @@ -14,6 +15,7 @@ export type ExportedSymbol =
| EnumDefinition
| ErrorDefinition
| FunctionDefinition
| UserDefinedValueTypeDefinition
| VariableDeclaration
| ImportDirective;

Expand Down Expand Up @@ -135,6 +137,15 @@ export class SourceUnit extends ASTNodeWithChildren<ASTNode> {
) as VariableDeclaration[];
}

/**
* References to file-level user-defined value type definitions
*/
get vUserDefinedValueTypes(): readonly UserDefinedValueTypeDefinition[] {
return this.ownChildren.filter(
(node) => node instanceof UserDefinedValueTypeDefinition
) as UserDefinedValueTypeDefinition[];
}

/**
* Referenced exported symbols
*/
Expand Down
10 changes: 9 additions & 1 deletion src/ast/modern/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EventDefinition } from "../implementation/declaration/event_definition"
import { FunctionDefinition } from "../implementation/declaration/function_definition";
import { ModifierDefinition } from "../implementation/declaration/modifier_definition";
import { StructDefinition } from "../implementation/declaration/struct_definition";
import { UserDefinedValueTypeDefinition } from "../implementation/declaration/user_defined_value_type_definition";
import { VariableDeclaration } from "../implementation/declaration/variable_declaration";
import { Assignment } from "../implementation/expression/assignment";
import { BinaryOperation } from "../implementation/expression/binary_operation";
Expand Down Expand Up @@ -109,6 +110,7 @@ import { ModernTupleExpressionProcessor } from "./tuple_expression_processor";
import { ModernUnaryOperationProcessor } from "./unary_operation_processor";
import { ModernUncheckedBlockProcessor } from "./unchecked_block_processor";
import { ModernUserDefinedTypeNameProcessor } from "./user_defined_type_name_processor";
import { ModernUserDefinedValueTypeDefinitionProcessor } from "./user_defined_value_type_definition_processor";
import { ModernUsingForDirectiveProcessor } from "./using_for_directive_processor";
import { ModernVariableDeclarationProcessor } from "./variable_declaration_processor";
import { ModernVariableDeclarationStatementProcessor } from "./variable_declaration_statement_processor";
Expand Down Expand Up @@ -178,7 +180,8 @@ const processors = {
Break: new ModernBreakProcessor(),
Continue: new ModernContinueProcessor(),
PlaceholderStatement: new ModernPlaceholderStatementProcessor(),
Throw: new ModernThrowProcessor()
Throw: new ModernThrowProcessor(),
UserDefinedValueTypeDefinition: new ModernUserDefinedValueTypeDefinitionProcessor()
};

export const ModernConfiguration: ASTReaderConfiguration = {
Expand Down Expand Up @@ -468,6 +471,11 @@ export const ModernConfiguration: ASTReaderConfiguration = {
Throw: {
constructor: Throw,
processor: processors.Throw
},

UserDefinedValueTypeDefinition: {
constructor: UserDefinedValueTypeDefinition,
processor: processors.UserDefinedValueTypeDefinition
}
}
};
1 change: 1 addition & 0 deletions src/ast/modern/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export * from "./type_name_processor";
export * from "./unary_operation_processor";
export * from "./unchecked_block_processor";
export * from "./user_defined_type_name_processor";
export * from "./user_defined_value_type_definition_processor";
export * from "./using_for_directive_processor";
export * from "./variable_declaration_processor";
export * from "./variable_declaration_statement_processor";
Expand Down
21 changes: 21 additions & 0 deletions src/ast/modern/user_defined_value_type_definition_processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ASTReader, ASTReaderConfiguration } from "../ast_reader";
import { UserDefinedValueTypeDefinition } from "../implementation/declaration/user_defined_value_type_definition";
import { ElementaryTypeName } from "../implementation/type/elementary_type_name";
import { ModernNodeProcessor } from "./node_processor";

export class ModernUserDefinedValueTypeDefinitionProcessor extends ModernNodeProcessor<UserDefinedValueTypeDefinition> {
process(
reader: ASTReader,
config: ASTReaderConfiguration,
raw: any
): ConstructorParameters<typeof UserDefinedValueTypeDefinition> {
const [id, src, type] = super.process(reader, config, raw);

const name: string = raw.name;
const canonicalName: string = raw.canonicalName;
const nameLocation: string | undefined = raw.nameLocation;
const underlyingType = reader.convert(raw.underlyingType, config) as ElementaryTypeName;

return [id, src, type, name, canonicalName, underlyingType, nameLocation, raw];
}
}
10 changes: 9 additions & 1 deletion src/ast/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
UnaryOperation,
UncheckedBlock,
UserDefinedTypeName,
UserDefinedValueTypeDefinition,
UsingForDirective,
VariableDeclaration,
VariableDeclarationStatement,
Expand Down Expand Up @@ -401,7 +402,8 @@ export function checkSane(unit: SourceUnit, ctx: ASTContext): void {
"vStructs",
"vFunctions",
"vVariables",
"vErrors"
"vErrors",
"vUserDefinedValueTypes"
);
} else if (node instanceof ImportDirective) {
/**
Expand Down Expand Up @@ -479,6 +481,7 @@ export function checkSane(unit: SourceUnit, ctx: ASTContext): void {
"vUsingForDirectives",
"vStructs",
"vEnums",
"vUserDefinedValueTypes",
"vConstructor"
];

Expand Down Expand Up @@ -557,6 +560,11 @@ export function checkSane(unit: SourceUnit, ctx: ASTContext): void {
checkVFieldCtx(node, "vScope", ctx);

checkDirectChildren(node, "vMembers");
} else if (node instanceof UserDefinedValueTypeDefinition) {
checkVFieldCtx(node, "vScope", ctx);
checkVFieldCtx(node, "underlyingType", ctx);

checkDirectChildren(node, "underlyingType");
} else if (node instanceof VariableDeclaration) {
checkFieldAndVFieldMatch(node, "scope", "vScope");
checkVFieldCtx(node, "vScope", ctx);
Expand Down
Loading

0 comments on commit 013c0d7

Please sign in to comment.