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.22 #234

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
304 changes: 159 additions & 145 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@
"prepare": "npm run build"
},
"dependencies": {
"axios": "^1.5.1",
"axios": "^1.6.0",
"commander": "^11.1.0",
"decimal.js": "^10.4.3",
"findup-sync": "^5.0.0",
"fs-extra": "^11.1.1",
"jsel": "^1.1.6",
"semver": "^7.5.4",
"solc": "^0.8.21",
"solc": "^0.8.22",
"src-location": "^1.1.0",
"web3-eth-abi": "^4.1.3"
"web3-eth-abi": "^4.1.4"
},
"devDependencies": {
"@types/fs-extra": "^11.0.3",
"@types/mocha": "^10.0.3",
"@types/node": "^16.18.59",
"@types/semver": "^7.5.4",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.51.0",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"expect": "^29.7.0",
Expand All @@ -55,7 +55,7 @@
"prettier": "3.0.3",
"ts-node": "^10.9.1",
"ts-pegjs": "^3.1.0",
"typedoc": "^0.25.2",
"typedoc": "^0.25.3",
"typescript": "^5.2.2"
},
"homepage": "https://consensys.github.io/solc-typed-ast",
Expand Down
1 change: 1 addition & 0 deletions src/ast/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ function* lookupInSourceUnit(
child instanceof ContractDefinition ||
child instanceof StructDefinition ||
child instanceof EnumDefinition ||
child instanceof EventDefinition ||
child instanceof ErrorDefinition ||
child instanceof UserDefinedValueTypeDefinition) &&
child.name === name
Expand Down
52 changes: 32 additions & 20 deletions src/ast/implementation/meta/source_unit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ABIEncoderVersion, ABIEncoderVersions } from "../../../types";
import { ASTNode, ASTNodeWithChildren } from "../../ast_node";
import { EventDefinition } from "../declaration";
import { ContractDefinition } from "../declaration/contract_definition";
import { EnumDefinition } from "../declaration/enum_definition";
import { ErrorDefinition } from "../declaration/error_definition";
Expand All @@ -17,6 +18,7 @@ export type ExportedSymbol =
| EnumDefinition
| ErrorDefinition
| FunctionDefinition
| EventDefinition
| UserDefinedValueTypeDefinition
| VariableDeclaration
| ImportDirective;
Expand Down Expand Up @@ -78,89 +80,99 @@ export class SourceUnit extends ASTNodeWithChildren<ASTNode> {
*/
get vPragmaDirectives(): readonly PragmaDirective[] {
return this.ownChildren.filter(
(node) => node instanceof PragmaDirective
) as PragmaDirective[];
(node): node is PragmaDirective => node instanceof PragmaDirective
);
}

/**
* References to import directives
*/
get vImportDirectives(): readonly ImportDirective[] {
return this.ownChildren.filter(
(node) => node instanceof ImportDirective
) as ImportDirective[];
(node): node is ImportDirective => node instanceof ImportDirective
);
}

/**
* References to contract definitions
*/
get vContracts(): readonly ContractDefinition[] {
return this.ownChildren.filter(
(node) => node instanceof ContractDefinition
) as ContractDefinition[];
(node): node is ContractDefinition => node instanceof ContractDefinition
);
}

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

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

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

/**
* References to file-level function definitions (free functions)
*/
get vFunctions(): readonly FunctionDefinition[] {
return this.ownChildren.filter(
(node) => node instanceof FunctionDefinition
) as FunctionDefinition[];
(node): node is FunctionDefinition => node instanceof FunctionDefinition
);
}

/**
* References to file-level event definitions
*/
get vEvents(): readonly EventDefinition[] {
return this.ownChildren.filter(
(node): node is EventDefinition => node instanceof EventDefinition
);
}

/**
* References to file-level constant variable definitions
*/
get vVariables(): readonly VariableDeclaration[] {
return this.ownChildren.filter(
(node) => node instanceof VariableDeclaration
) as VariableDeclaration[];
(node): node is VariableDeclaration => node instanceof VariableDeclaration
);
}

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

/**
* References to file-level using-for directives
*/
get vUsingForDirectives(): readonly UsingForDirective[] {
return this.ownChildren.filter(
(node) => node instanceof UsingForDirective
) as UsingForDirective[];
(node): node is UsingForDirective => node instanceof UsingForDirective
);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/ast/writing/ast_mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,12 @@ class SourceUnitWriter extends ASTNodeWriter {
result.push(...flatten(node.vVariables.map((n) => [...writeFn(n), ";", wrap])), wrap);
}

const otherDefs = [...node.vErrors, ...node.vFunctions, ...node.vContracts];
const otherDefs = [
...node.vErrors,
...node.vEvents,
...node.vFunctions,
...node.vContracts
];

if (otherDefs.length > 0) {
result.push(...flatJoin(otherDefs.map(writeLineFn), wrap));
Expand Down
3 changes: 2 additions & 1 deletion src/compile/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export const CompilerVersions08 = [
"0.8.18",
"0.8.19",
"0.8.20",
"0.8.21"
"0.8.21",
"0.8.22"
];

export const CompilerSeries = [
Expand Down
14 changes: 14 additions & 0 deletions src/compile/inference/file_level_definitions.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ FileLevelDefinition =
/ FreeFunction
/ ContractDefinition
/ EnumDef
/ EventDef
/ ErrorDef
/ StructDef
/ UserValueTypeDef
Expand Down Expand Up @@ -143,6 +144,18 @@ EnumDef = ENUM __ name: Identifier __ body: EnumDefBody {
} as FLEnumDefinition;
}

// ==== Event

EventArgs = LPAREN __ ParenSoup __ RPAREN { return text(); }
EventDef = EVENT __ name: Identifier __ args: EventArgs __ SEMICOLON {
blitz-1306 marked this conversation as resolved.
Show resolved Hide resolved
return {
kind: FileLevelNodeKind.Event,
location: location(),
name,
args
} as FLEventDefinition;
}

// ==== Error

ErrorArgs = LPAREN __ ParenSoup __ RPAREN { return text(); }
Expand Down Expand Up @@ -323,6 +336,7 @@ TYPE = "type"
RETURNS = "returns"
PRAGMA = "pragma"
ERROR = "error"
EVENT = "event"
USING = "using"
FOR = "for"
GLOBAL = "global"
Expand Down
12 changes: 10 additions & 2 deletions src/compile/inference/file_level_definitions_parser_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum FileLevelNodeKind {
Struct = "struct",
Enum = "enum",
Error = "error",
Event = "event",
UserValueType = "userValueType",
UsingForDirective = "usingForDirective"
}
Expand Down Expand Up @@ -65,6 +66,11 @@ export interface FLEnumDefinition extends FileLevelNode<FileLevelNodeKind.Enum>
body: string;
}

export interface FLEventDefinition extends FileLevelNode<FileLevelNodeKind.Event> {
name: string;
args: string;
blitz-1306 marked this conversation as resolved.
Show resolved Hide resolved
}

export interface FLErrorDefinition extends FileLevelNode<FileLevelNodeKind.Error> {
name: string;
args: string;
Expand All @@ -82,17 +88,19 @@ export interface FLCustomizableOperator {

export interface FLUsingForDirective extends FileLevelNode<FileLevelNodeKind.UsingForDirective> {
libraryName?: string;
functionList?: Array<string | FLCustomizableOperator>;
functionList?: Array<string | FLCustomizableOperator>;
typeName: string;
isGlobal: boolean;
}

export type AnyFileLevelNode = FLPragma
export type AnyFileLevelNode =
| FLPragma
| FLImportDirective
| FLConstant
| FLFreeFunction
| FLContractDefinition
| FLStructDefinition
| FLEventDefinition
| FLEnumDefinition
| FLErrorDefinition
| FLUserValueType
Expand Down
4 changes: 4 additions & 0 deletions src/types/infer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,10 @@ export class InferType {
return this.funDefToType(originalSym);
}

if (originalSym instanceof EventDefinition) {
return this.eventDefToType(originalSym);
}

return this.variableDeclarationToTypeNode(originalSym);
}
}
Expand Down
32 changes: 16 additions & 16 deletions test/integration/compile/latest_08.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@ const encounters = new Map<string, number>([
["ImportDirective", 1],
["StructDefinition", 1],
["StructuredDocumentation", 5],
["VariableDeclaration", 75],
["ElementaryTypeName", 58],
["VariableDeclaration", 79],
["ElementaryTypeName", 62],
["EnumDefinition", 2],
["EnumValue", 6],
["ContractDefinition", 18],
["FunctionDefinition", 34],
["ParameterList", 87],
["Block", 50],
["ContractDefinition", 21],
["FunctionDefinition", 35],
["ParameterList", 93],
["Block", 51],
["VariableDeclarationStatement", 16],
["Literal", 38],
["Literal", 42],
["UncheckedBlock", 4],
["ExpressionStatement", 22],
["UnaryOperation", 6],
["Identifier", 93],
["Identifier", 97],
["Return", 15],
["InheritanceSpecifier", 1],
["IdentifierPath", 36],
["UsingForDirective", 3],
["UserDefinedTypeName", 27],
["ModifierInvocation", 2],
["FunctionCall", 42],
["MemberAccess", 38],
["FunctionCall", 46],
["MemberAccess", 41],
["OverrideSpecifier", 1],
["ElementaryTypeNameExpression", 4],
["NewExpression", 2],
["TryStatement", 2],
["TryCatchClause", 8],
["IfStatement", 3],
["BinaryOperation", 23],
["EventDefinition", 2],
["EventDefinition", 6],
["ModifierDefinition", 1],
["PlaceholderStatement", 1],
["TupleExpression", 9],
["EmitStatement", 1],
["EmitStatement", 5],
["WhileStatement", 1],
["Continue", 1],
["DoWhileStatement", 1],
Expand Down Expand Up @@ -117,11 +117,11 @@ for (const compilerKind of PossibleCompilerKinds) {
// console.log(sourceUnit.print());
// console.log(sourceUnit.getChildren().length);

expect(sourceUnit.id).toEqual(776);
expect(sourceUnit.src).toEqual("0:9048:0");
expect(sourceUnit.id).toEqual(821);
expect(sourceUnit.src).toEqual("0:9351:0");
expect(sourceUnit.absolutePath).toEqual(mainSample);
expect(sourceUnit.children.length).toEqual(32);
expect(sourceUnit.getChildren().length).toEqual(769);
expect(sourceUnit.children.length).toEqual(36);
expect(sourceUnit.getChildren().length).toEqual(811);
});

it(`Validate parsed output (${astKind})`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SourceUnit #146
<getter> vErrors: Array(0)
<getter> vStructs: Array(0)
<getter> vFunctions: Array(0)
<getter> vEvents: Array(0)
<getter> vVariables: Array(0)
<getter> vUserDefinedValueTypes: Array(0)
<getter> vUsingForDirectives: Array(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SourceUnit #146
<getter> vErrors: Array(0)
<getter> vStructs: Array(0)
<getter> vFunctions: Array(0)
<getter> vEvents: Array(0)
<getter> vVariables: Array(0)
<getter> vUserDefinedValueTypes: Array(0)
<getter> vUsingForDirectives: Array(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SourceUnit #21
<getter> vErrors: Array(0)
<getter> vStructs: Array(0)
<getter> vFunctions: Array(0)
<getter> vEvents: Array(0)
<getter> vVariables: Array(0)
<getter> vUserDefinedValueTypes: Array(0)
<getter> vUsingForDirectives: Array(0)
Expand Down Expand Up @@ -158,6 +159,7 @@ SourceUnit #30
<getter> vErrors: Array(0)
<getter> vStructs: Array(0)
<getter> vFunctions: Array(0)
<getter> vEvents: Array(0)
<getter> vVariables: Array(0)
<getter> vUserDefinedValueTypes: Array(0)
<getter> vUsingForDirectives: Array(0)
Expand Down
Loading