Skip to content

Commit

Permalink
Merge pull request #57 from ConsenSys/support-solidity-087
Browse files Browse the repository at this point in the history
Support for Solidity 0.8.7
  • Loading branch information
blitz-1306 authored Aug 24, 2021
2 parents 3827083 + ecb77aa commit 35d7167
Show file tree
Hide file tree
Showing 13 changed files with 3,330 additions and 2,817 deletions.
570 changes: 345 additions & 225 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 @@ -90,29 +90,30 @@
"solc-0.8.4": "npm:[email protected]",
"solc-0.8.5": "npm:[email protected]",
"solc-0.8.6": "npm:[email protected]",
"solc-0.8.7": "npm:[email protected]",
"src-location": "^1.1.0",
"web3-eth-abi": "^1.4.0"
"web3-eth-abi": "^1.5.2"
},
"devDependencies": {
"@types/fs-extra": "^9.0.12",
"@types/minimist": "^1.2.2",
"@types/mocha": "^8.2.3",
"@types/node": "^12.20.16",
"@types/semver": "^7.3.7",
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"@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",
"codecov": "^3.8.3",
"eslint": "^7.31.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-prettier": "^3.4.1",
"expect": "^27.0.6",
"mocha": "^9.0.2",
"mocha": "^9.1.0",
"nyc": "^15.1.0",
"peggy": "^1.2.0",
"prettier": "2.3.2",
"ts-node": "^10.1.0",
"ts-node": "^10.2.1",
"ts-pegjs": "^1.1.1",
"typedoc": "^0.21.4",
"typedoc": "^0.21.6",
"typescript": "^4.3.5"
},
"homepage": "https://consensys.github.io/solc-typed-ast",
Expand Down
51 changes: 28 additions & 23 deletions src/bin/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
XPath
} from "..";

const modes = ["auto", "sol", "json"];

const cli = {
boolean: [
"version",
Expand All @@ -42,13 +44,11 @@ const cli = {
string: ["mode", "compiler-version", "path-remapping", "xpath"],
default: {
depth: Number.MAX_SAFE_INTEGER,
mode: "auto",
mode: modes[0],
"compiler-version": "auto"
}
};

const modes = ["auto", "sol", "json"];

const args = minimist(process.argv.slice(2), cli);

if (args.version) {
Expand Down Expand Up @@ -78,14 +78,14 @@ OPTIONS:
--stdin Read input from STDIN instead of files.
Requires "mode" to be explicitly set to "sol" or "json".
--mode One of the following input types:
- sol (Solidity source)
- json (JSON compiler artifact)
- auto (try to detect by file extension)
Default value: auto
- ${modes[1]} (Solidity source)
- ${modes[2]} (JSON compiler artifact)
- ${modes[0]} (try to detect by file extension)
Default value: ${cli.default.mode}
--compiler-version Solc version to use:
- ${LatestCompilerVersion} (exact SemVer version specifier)
- auto (try to detect suitable compiler version)
Default value: auto
Default value: ${cli.default["compiler-version"]}
--path-remapping Path remapping input for Solc.
--raw Print raw Solc compilation output.
--with-sources When used with "raw", adds "source" property with
Expand All @@ -95,7 +95,7 @@ OPTIONS:
--xpath XPath selector to perform for each source unit.
--depth Number of children for each of AST node to print.
Minimum value is 0. Not affects "raw", "tree" and "source".
Default value: ${Number.MAX_SAFE_INTEGER}
Default value: ${cli.default.depth}
`;

console.log(message);
Expand Down Expand Up @@ -135,20 +135,19 @@ OPTIONS:

const content = fse.readFileSync(0, { encoding: "utf-8" });

if (mode === "json") {
const data = JSON.parse(content);

result = compileJsonData(fileName, data, compilerVersion, pathRemapping);
} else {
result = compileSourceString(fileName, content, compilerVersion, pathRemapping);
}
result =
mode === "json"
? compileJsonData(fileName, JSON.parse(content), compilerVersion, pathRemapping)
: compileSourceString(fileName, content, compilerVersion, pathRemapping);
} else {
fileName = path.resolve(process.cwd(), args._[0]);

if (mode === "auto") {
if (fileName.toLowerCase().endsWith(".sol")) {
const iFileName = fileName.toLowerCase();

if (iFileName.endsWith(".sol")) {
result = compileSol(fileName, compilerVersion, pathRemapping);
} else if (fileName.toLowerCase().endsWith(".json")) {
} else if (iFileName.endsWith(".json")) {
result = compileJson(fileName, compilerVersion, pathRemapping);
} else {
throw new Error("Unable to auto-detect mode for the file name: " + fileName);
Expand Down Expand Up @@ -291,12 +290,18 @@ OPTIONS:
}

if (args.source) {
let targetCompilerVersion: string;

if (result.compilerVersion) {
targetCompilerVersion = result.compilerVersion;
} else if (compilerVersion !== "auto") {
targetCompilerVersion = compilerVersion;
} else {
targetCompilerVersion = LatestCompilerVersion;
}

const formatter = new PrettyFormatter(4, 0);
const writer = new ASTWriter(
DefaultASTWriterMapping,
formatter,
result.compilerVersion ? result.compilerVersion : LatestCompilerVersion
);
const writer = new ASTWriter(DefaultASTWriterMapping, formatter, targetCompilerVersion);

for (const unit of units) {
console.log("// " + separator);
Expand Down
11 changes: 10 additions & 1 deletion src/compile/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ export const CompilerVersions06 = [

export const CompilerVersions07 = ["0.7.0", "0.7.1", "0.7.2", "0.7.3", "0.7.4", "0.7.5", "0.7.6"];

export const CompilerVersions08 = ["0.8.0", "0.8.1", "0.8.2", "0.8.3", "0.8.4", "0.8.5", "0.8.6"];
export const CompilerVersions08 = [
"0.8.0",
"0.8.1",
"0.8.2",
"0.8.3",
"0.8.4",
"0.8.5",
"0.8.6",
"0.8.7"
];

export const CompilerSeries = [
CompilerVersions04,
Expand Down
4 changes: 1 addition & 3 deletions test/integration/compile/04.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe(`Compile ${sample} with any available 0.4.x compiler`, () => {
let data: any = {};
let sourceUnits: SourceUnit[];

before("Compile", (done) => {
before("Compile", () => {
const result = compileSol(sample, version, []);

expect(result.compilerVersion).toEqual(version);
Expand All @@ -65,8 +65,6 @@ describe(`Compile ${sample} with any available 0.4.x compiler`, () => {
expect(errors).toHaveLength(0);

data = result.data;

done();
});

it("Process compiler output", () => {
Expand Down
4 changes: 1 addition & 3 deletions test/integration/compile/05.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe(`Compile ${sample} with any available 0.5.x compiler`, () => {
let data: any = {};
let sourceUnits: SourceUnit[];

before("Compile", (done) => {
before("Compile", () => {
const result = compileSol(sample, version, []);

expect(result.compilerVersion).toEqual(version);
Expand All @@ -65,8 +65,6 @@ describe(`Compile ${sample} with any available 0.5.x compiler`, () => {
expect(errors).toHaveLength(0);

data = result.data;

done();
});

for (const kind of [ASTKind.Modern, ASTKind.Legacy]) {
Expand Down
4 changes: 1 addition & 3 deletions test/integration/compile/06.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe(`Compile ${sample} with any available 0.6.x compiler`, () => {
let data: any = {};
let sourceUnits: SourceUnit[];

before("Compile", (done) => {
before("Compile", () => {
const result = compileSol(sample, version, []);

expect(result.compilerVersion).toEqual(version);
Expand All @@ -68,8 +68,6 @@ describe(`Compile ${sample} with any available 0.6.x compiler`, () => {
expect(errors).toHaveLength(0);

data = result.data;

done();
});

for (const kind of [ASTKind.Modern, ASTKind.Legacy]) {
Expand Down
4 changes: 1 addition & 3 deletions test/integration/compile/latest_06.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe(`Compile ${sample} with ${compilerVersion} compiler`, () => {
let data: any = {};
let sourceUnits: SourceUnit[];

before("Compile", (done) => {
before("Compile", () => {
const result = compileSol(sample, "auto", []);

expect(result.compilerVersion).toEqual(compilerVersion);
Expand All @@ -75,8 +75,6 @@ describe(`Compile ${sample} with ${compilerVersion} compiler`, () => {
expect(errors).toHaveLength(0);

data = result.data;

done();
});

for (const kind of [ASTKind.Modern, ASTKind.Legacy]) {
Expand Down
4 changes: 1 addition & 3 deletions test/integration/compile/latest_07.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe(`Compile ${sample} with ${compilerVersion} compiler`, () => {
let data: any = {};
let sourceUnits: SourceUnit[];

before("Compile", (done) => {
before("Compile", () => {
const result = compileSol(sample, "auto", []);

expect(result.compilerVersion).toEqual(compilerVersion);
Expand All @@ -66,8 +66,6 @@ describe(`Compile ${sample} with ${compilerVersion} compiler`, () => {
expect(errors).toHaveLength(0);

data = result.data;

done();
});

for (const kind of [ASTKind.Modern, ASTKind.Legacy]) {
Expand Down
32 changes: 15 additions & 17 deletions test/integration/compile/latest_08.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ const encounters = new Map<string, number>([
["ImportDirective", 1],
["EnumDefinition", 2],
["EnumValue", 6],
["ContractDefinition", 7],
["FunctionDefinition", 13],
["ParameterList", 35],
["VariableDeclaration", 21],
["ElementaryTypeName", 21],
["Block", 30],
["ContractDefinition", 8],
["FunctionDefinition", 15],
["ParameterList", 39],
["VariableDeclaration", 23],
["ElementaryTypeName", 23],
["Block", 32],
["VariableDeclarationStatement", 9],
["Literal", 21],
["UncheckedBlock", 2],
["ExpressionStatement", 7],
["UnaryOperation", 2],
["Identifier", 20],
["Return", 4],
["Identifier", 21],
["Return", 5],
["InheritanceSpecifier", 1],
["IdentifierPath", 11],
["UsingForDirective", 1],
["UserDefinedTypeName", 6],
["ModifierInvocation", 2],
["FunctionCall", 16],
["MemberAccess", 8],
["MemberAccess", 9],
["OverrideSpecifier", 1],
["ElementaryTypeNameExpression", 3],
["NewExpression", 2],
Expand All @@ -65,7 +65,7 @@ const encounters = new Map<string, number>([
["DoWhileStatement", 1],
["Break", 1],
["ForStatement", 1],
["InlineAssembly", 2],
["InlineAssembly", 3],
["ErrorDefinition", 3],
["StructuredDocumentation", 3],
["RevertStatement", 3]
Expand All @@ -77,7 +77,7 @@ describe(`Compile ${mainSample} with ${compilerVersion} compiler`, () => {
let data: any = {};
let sourceUnits: SourceUnit[];

before("Compile", (done) => {
before("Compile", () => {
const result = compileSol(mainSample, "auto", []);

expect(result.compilerVersion).toEqual(compilerVersion);
Expand All @@ -88,8 +88,6 @@ describe(`Compile ${mainSample} with ${compilerVersion} compiler`, () => {
expect(errors).toHaveLength(0);

data = result.data;

done();
});

it(`Parse compiler output (${kind})`, () => {
Expand All @@ -101,11 +99,11 @@ describe(`Compile ${mainSample} with ${compilerVersion} compiler`, () => {

const sourceUnit = sourceUnits[0];

expect(sourceUnit.id).toEqual(298);
expect(sourceUnit.src).toEqual("0:4474:0");
expect(sourceUnit.id).toEqual(315);
expect(sourceUnit.src).toEqual("0:4733:0");
expect(sourceUnit.absolutePath).toEqual(mainSample);
expect(sourceUnit.children.length).toEqual(12);
expect(sourceUnit.getChildren().length).toEqual(292);
expect(sourceUnit.children.length).toEqual(13);
expect(sourceUnit.getChildren().length).toEqual(309);
});

it(`Validate parsed output (${kind})`, () => {
Expand Down
Loading

0 comments on commit 35d7167

Please sign in to comment.