Skip to content

Commit

Permalink
Merge pull request #107 from ConsenSys/support-solidity-0813
Browse files Browse the repository at this point in the history
Support for Solidity 0.8.13
  • Loading branch information
blitz-1306 authored Mar 23, 2022
2 parents 1dc7584 + c2ffabe commit 381d42d
Show file tree
Hide file tree
Showing 24 changed files with 15,389 additions and 10,339 deletions.
654 changes: 372 additions & 282 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 @@ -34,7 +34,7 @@
"jsel": "^1.1.6",
"minimist": "^1.2.5",
"semver": "^7.3.5",
"solc": "^0.8.12",
"solc": "^0.8.13",
"src-location": "^1.1.0",
"web3-eth-abi": "^1.7.1"
},
Expand All @@ -44,19 +44,19 @@
"@types/mocha": "^9.1.0",
"@types/node": "^16.11.26",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"codecov": "^3.8.3",
"eslint": "^8.10.0",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"expect": "^27.5.1",
"mocha": "^9.2.1",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"peggy": "^1.2.0",
"prettier": "2.5.1",
"prettier": "2.6.0",
"ts-node": "^10.7.0",
"ts-pegjs": "^1.2.1",
"ts-pegjs": "^1.2.2",
"typedoc": "^0.22.13",
"typescript": "^4.6.2"
},
Expand Down
5 changes: 5 additions & 0 deletions src/ast/ast_node_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ const argExtractionMapping = new Map<ASTNodeConstructor<ASTNode>, (node: any) =>
[
UsingForDirective,
(node: UsingForDirective): Specific<ConstructorParameters<typeof UsingForDirective>> => [
node.isGlobal,
node.vLibraryName,
node.vFunctionList,
node.vTypeName,
node.raw
]
Expand Down Expand Up @@ -531,6 +533,8 @@ const argExtractionMapping = new Map<ASTNodeConstructor<ASTNode>, (node: any) =>
node.externalReferences,
node.operations,
node.yul,
node.flags,
node.evmVersion,
node.documentation,
node.raw
]
Expand Down Expand Up @@ -1143,6 +1147,7 @@ export class ASTNodeFactory {

if (
node instanceof Identifier ||
node instanceof IdentifierPath ||
node instanceof MemberAccess ||
node instanceof UserDefinedTypeName
) {
Expand Down
10 changes: 10 additions & 0 deletions src/ast/implementation/meta/source_unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { UserDefinedValueTypeDefinition } from "../declaration/user_defined_valu
import { VariableDeclaration } from "../declaration/variable_declaration";
import { ImportDirective } from "./import_directive";
import { PragmaDirective } from "./pragma_directive";
import { UsingForDirective } from "./using_for_directive";

export type ExportedSymbol =
| ContractDefinition
Expand Down Expand Up @@ -145,6 +146,15 @@ export class SourceUnit extends ASTNodeWithChildren<ASTNode> {
) as UserDefinedValueTypeDefinition[];
}

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

/**
* Referenced exported symbols
*/
Expand Down
33 changes: 28 additions & 5 deletions src/ast/implementation/meta/using_for_directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,54 @@ import { IdentifierPath } from "./identifier_path";

export class UsingForDirective extends ASTNode {
/**
* A library type
* A library type name or identifier.
* One of vLibraryName or vFunctionList should always be set.
*/
vLibraryName: UserDefinedTypeName | IdentifierPath;
vLibraryName?: UserDefinedTypeName | IdentifierPath;

/**
* Function list for file-level using-for directives.
* One of vLibraryName or vFunctionList should always be set.
*/
vFunctionList?: IdentifierPath[];

/**
* A target type name that the library functions will apply to.
*/
vTypeName?: TypeName;

/**
* Allows to apply vLibraryName or vFunctionList to the type everywhere,
* where type is accessible.
*/
isGlobal: boolean;

constructor(
id: number,
src: string,
libraryName: UserDefinedTypeName | IdentifierPath,
isGlobal: boolean,
libraryName?: UserDefinedTypeName | IdentifierPath,
functionList?: IdentifierPath[],
typeName?: TypeName,
raw?: any
) {
super(id, src, raw);

this.vLibraryName = libraryName;
if (libraryName) {
this.vLibraryName = libraryName;
} else if (functionList) {
this.vFunctionList = functionList;
} else {
throw new Error("One of vLibraryName or vFunctionList should always be set");
}

this.vTypeName = typeName;
this.isGlobal = isGlobal;

this.acceptChildren();
}

get children(): readonly ASTNode[] {
return this.pickNodes(this.vLibraryName, this.vTypeName);
return this.pickNodes(this.vLibraryName, this.vFunctionList, this.vTypeName);
}
}
7 changes: 7 additions & 0 deletions src/ast/implementation/statement/inline_assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ export class InlineAssembly extends Statement {
operations?: string;
yul?: YulNode;

flags?: string[];
evmVersion?: string;

constructor(
id: number,
src: string,
externalReferences: any[],
operations?: string,
yul?: YulNode,
flags?: string[],
evmVersion?: string,
documentation?: string | StructuredDocumentation,
raw?: any
) {
Expand All @@ -28,5 +33,7 @@ export class InlineAssembly extends Statement {
this.externalReferences = externalReferences;
this.operations = operations;
this.yul = yul;
this.flags = flags;
this.evmVersion = evmVersion;
}
}
2 changes: 1 addition & 1 deletion src/ast/legacy/inline_assembly_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export class LegacyInlineAssemblyProcessor extends LegacyNodeProcessor<InlineAss
*/
const yul = undefined;

return [id, src, externalReferences, operations, yul, undefined, raw];
return [id, src, externalReferences, operations, yul, undefined, undefined, undefined, raw];
}
}
9 changes: 8 additions & 1 deletion src/ast/legacy/using_for_directive_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export class LegacyUsingForDirectiveProcessor extends LegacyNodeProcessor<UsingF
TypeName?
];

return [id, src, libraryName, typeName, raw];
/**
* The "global" and "functionList" are only appearing since Solidity 0.8.13.
* The legacy AST should not ever contain these properties.
*/
const isGlobal = false;
const functionList = undefined;

return [id, src, isGlobal, libraryName, functionList, typeName, raw];
}
}
14 changes: 13 additions & 1 deletion src/ast/modern/inline_assembly_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ export class ModernInlineAssemblyProcessor extends ModernNodeProcessor<InlineAss
const documentation: string | undefined = raw.documentation;
const operations: string | undefined = raw.operations;
const yul: YulNode | undefined = raw.AST;
const flags: string[] | undefined = raw.flags;
const evmVersion: string | undefined = raw.evmVersion;

return [id, src, externalReferences, operations, yul, documentation, raw];
return [
id,
src,
externalReferences,
operations,
yul,
flags,
evmVersion,
documentation,
raw
];
}
}
16 changes: 14 additions & 2 deletions src/ast/modern/using_for_directive_processor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ASTReader, ASTReaderConfiguration } from "../ast_reader";
import { IdentifierPath } from "../implementation/meta";
import { UsingForDirective } from "../implementation/meta/using_for_directive";
import { TypeName } from "../implementation/type/type_name";
import { UserDefinedTypeName } from "../implementation/type/user_defined_type_name";
Expand All @@ -12,11 +13,22 @@ export class ModernUsingForDirectiveProcessor extends ModernNodeProcessor<UsingF
): ConstructorParameters<typeof UsingForDirective> {
const [id, src] = super.process(reader, config, raw);

const libraryName = reader.convert(raw.libraryName, config) as UserDefinedTypeName;
const libraryName = raw.libraryName
? (reader.convert(raw.libraryName, config) as UserDefinedTypeName)
: undefined;

const functionList: IdentifierPath[] | undefined = raw.functionList
? raw.functionList.map(
(entry: any) => reader.convert(entry.function, config) as IdentifierPath
)
: undefined;

const typeName = raw.typeName
? (reader.convert(raw.typeName, config) as TypeName)
: undefined;

return [id, src, libraryName, typeName, raw];
const isGlobal = raw.global === true;

return [id, src, isGlobal, libraryName, functionList, typeName, raw];
}
}
5 changes: 3 additions & 2 deletions src/ast/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ export function checkSane(unit: SourceUnit, ctx: ASTContext): void {
"vFunctions",
"vVariables",
"vErrors",
"vUserDefinedValueTypes"
"vUserDefinedValueTypes",
"vUsingForDirectives"
);
} else if (node instanceof ImportDirective) {
/**
Expand Down Expand Up @@ -451,7 +452,7 @@ export function checkSane(unit: SourceUnit, ctx: ASTContext): void {
checkVFieldCtx(node, "vParameters", ctx);
checkDirectChildren(node, "vParameters");
} else if (node instanceof UsingForDirective) {
checkDirectChildren(node, "vLibraryName", "vTypeName");
checkDirectChildren(node, "vLibraryName", "vFunctionList", "vTypeName");
} else if (node instanceof ContractDefinition) {
checkFieldAndVFieldMatch(node, "scope", "vScope");
checkVFieldCtx(node, "vScope", ctx);
Expand Down
55 changes: 39 additions & 16 deletions src/ast/writing/ast_mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,23 +720,25 @@ class PlaceholderStatementWriter extends SimpleStatementWriter<PlaceholderStatem

class InlineAssemblyWriter extends ASTNodeWriter {
writeInner(node: InlineAssembly, writer: ASTWriter): SrcDesc {
let yul: string | undefined;
const result: SrcDesc = ["assembly "];

if (node.operations !== undefined) {
yul = node.operations;
if (node.flags !== undefined) {
const quotedFlags = node.flags.map((flag) => `"${flag}"`);

result.push("(", ...join(quotedFlags, ", "), ") ");
}

if (node.yul !== undefined) {
if (node.operations !== undefined) {
result.push(node.operations);
} else if (node.yul !== undefined) {
const yulWriter = new YulWriter(DefaultYulWriterMapping, writer.formatter);

yul = yulWriter.write(node.yul);
}

if (yul === undefined) {
result.push(yulWriter.write(node.yul));
} else {
throw new Error("Unable to detect Yul data in inline assembly node: " + node.print());
}

return ["assembly " + yul];
return result;
}

writeWhole(node: InlineAssembly, writer: ASTWriter): SrcDesc {
Expand Down Expand Up @@ -1118,13 +1120,30 @@ class FunctionDefinitionWriter extends ASTNodeWriter {

class UsingForDirectiveWriter extends ASTNodeWriter {
writeInner(node: UsingForDirective, writer: ASTWriter): SrcDesc {
return writer.desc(
"using ",
node.vLibraryName,
" for ",
node.vTypeName ? node.vTypeName : "*",
";"
);
const result: DescArgs = ["using "];

if (
(node.vLibraryName && node.vFunctionList) ||
!(node.vLibraryName || node.vFunctionList)
) {
throw new Error("Malformed using-for directive: " + node.print());
}

if (node.vLibraryName) {
result.push(node.vLibraryName);
} else if (node.vFunctionList) {
result.push("{ ", ...join(node.vFunctionList, ", "), " }");
}

result.push(" for ", node.vTypeName ? node.vTypeName : "*");

if (node.isGlobal) {
result.push(" global");
}

result.push(";");

return writer.desc(...result);
}
}

Expand Down Expand Up @@ -1324,6 +1343,10 @@ class SourceUnitWriter extends ASTNodeWriter {
result.push(...flatJoin(typeDefs.map(writeLineFn), wrap), wrap);
}

if (node.vUsingForDirectives.length > 0) {
result.push(...flatten(node.vUsingForDirectives.map(writeLineFn)), wrap);
}

if (node.vVariables.length > 0) {
result.push(...flatten(node.vVariables.map((n) => [...writeFn(n), ";", wrap])), 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 @@ -67,7 +67,8 @@ export const CompilerVersions08 = [
"0.8.9",
"0.8.10",
"0.8.11",
"0.8.12"
"0.8.12",
"0.8.13"
];

export const CompilerSeries = [
Expand Down
Loading

0 comments on commit 381d42d

Please sign in to comment.