Skip to content

Commit

Permalink
Merge pull request #133 from ConsenSys/function_kind.issue
Browse files Browse the repository at this point in the history
Fix for #132
  • Loading branch information
blitz-1306 authored Jul 19, 2022
2 parents 567729c + 2321e2e commit 2a06e9f
Show file tree
Hide file tree
Showing 7 changed files with 1,194 additions and 15 deletions.
17 changes: 3 additions & 14 deletions src/ast/legacy/function_definition_processor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ASTNode } from "../ast_node";
import { ASTReader, ASTReaderConfiguration } from "../ast_reader";
import { FunctionKind, FunctionStateMutability, FunctionVisibility } from "../constants";
import { FunctionStateMutability, FunctionVisibility } from "../constants";
import { FunctionDefinition } from "../implementation/declaration/function_definition";
import { ModifierInvocation } from "../implementation/meta/modifier_invocation";
import { OverrideSpecifier } from "../implementation/meta/override_specifier";
import { ParameterList } from "../implementation/meta/parameter_list";
import { StructuredDocumentation } from "../implementation/meta/structured_documentation";
import { Block } from "../implementation/statement/block";
import { detectFunctionKind } from "../utils";
import { LegacyNodeProcessor } from "./node_processor";

export class LegacyFunctionDefinitionProcessor extends LegacyNodeProcessor<FunctionDefinition> {
Expand All @@ -24,7 +25,7 @@ export class LegacyFunctionDefinitionProcessor extends LegacyNodeProcessor<Funct
const visibility: FunctionVisibility = attributes.visibility;
const virtual: boolean = "virtual" in attributes ? attributes.virtual : false;
const name: string = attributes.name;
const kind = this.detectFunctionKind(attributes);
const kind = detectFunctionKind(attributes);
const stateMutability = this.detectStateMutability(attributes);

const [
Expand Down Expand Up @@ -65,18 +66,6 @@ export class LegacyFunctionDefinitionProcessor extends LegacyNodeProcessor<Funct
];
}

private detectFunctionKind(attributes: any): FunctionKind {
if (attributes.kind) {
return attributes.kind;
}

if (attributes.isConstructor) {
return FunctionKind.Constructor;
}

return attributes.name === "" ? FunctionKind.Fallback : FunctionKind.Function;
}

private detectStateMutability(attributes: any): FunctionStateMutability {
if (attributes.stateMutability) {
return attributes.stateMutability;
Expand Down
3 changes: 2 additions & 1 deletion src/ast/modern/function_definition_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { OverrideSpecifier } from "../implementation/meta/override_specifier";
import { ParameterList } from "../implementation/meta/parameter_list";
import { StructuredDocumentation } from "../implementation/meta/structured_documentation";
import { Block } from "../implementation/statement/block";
import { detectFunctionKind } from "../utils";
import { ModernNodeProcessor } from "./node_processor";

export class ModernFunctionDefinitionProcessor extends ModernNodeProcessor<FunctionDefinition> {
Expand All @@ -17,7 +18,7 @@ export class ModernFunctionDefinitionProcessor extends ModernNodeProcessor<Funct
const [id, src] = super.process(reader, config, raw);

const scope: number = raw.scope;
const kind: FunctionKind = raw.kind;
const kind: FunctionKind = detectFunctionKind(raw);
const isConstructor: boolean = raw.isConstructor || raw.kind === FunctionKind.Constructor;
const visibility: FunctionVisibility = raw.visibility;
const virtual: boolean = "virtual" in raw ? raw.virtual : false;
Expand Down
13 changes: 13 additions & 0 deletions src/ast/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import coder from "web3-eth-abi";
import { FunctionKind } from "./constants";

export type SourceLocation = { offset: number; length: number; sourceIndex: number };

Expand Down Expand Up @@ -95,3 +96,15 @@ export function parseSourceLocation(range: string): SourceLocation {

return { offset, length, sourceIndex };
}

export function detectFunctionKind(attributes: any): FunctionKind {
if (attributes.kind) {
return attributes.kind;
}

if (attributes.isConstructor) {
return FunctionKind.Constructor;
}

return attributes.name === "" ? FunctionKind.Fallback : FunctionKind.Function;
}
7 changes: 7 additions & 0 deletions test/integration/factory/copy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ const cases: Array<[string, Array<[CompilerKind, string]>]> = [
]
]
],
[
"./test/samples/solidity/issue_132_fun_kind.sol",
[
[CompilerKind.WASM, "./test/samples/solidity/issue_132_fun_kind.nodes.wasm.txt"],
[CompilerKind.Native, "./test/samples/solidity/issue_132_fun_kind.nodes.native.txt"]
]
],
[
"./test/samples/solidity/latest_08.sol",
[
Expand Down
Loading

0 comments on commit 2a06e9f

Please sign in to comment.