solidity-ast icon indicating copy to clipboard operation
solidity-ast copied to clipboard

Provide types or helpers for common deref operations

Open frangio opened this issue 3 years ago • 3 comments

Let deref: ASTDereferencer, we could have additional helpers:

  • deref.functionCall(node: FunctionCall): FunctionDefinition | VariableDeclaration | undefined
  • deref.scope(node: FunctionDefinition | StructDefinition | ...): ContractDefinition | SourceUnit
  • deref.scope(node: VariableDeclaration): Block | ContractDefinition | SourceUnit
  • (...others)

Alternatively, we can provide arrays of node types for each of these use cases that could be passed in to deref function.

frangio avatar Dec 14 '22 22:12 frangio

From testing, I found the following although I'm not sure if these are exhaustive:

  • A FunctionCall's expression.referencedDeclaration can reference any of the following types: 'FunctionDefinition', 'EventDefinition', 'ContractDefinition', 'StructDefinition'
  • A ContractDefinition's scope can reference any of the following types: 'ContractDefinition', 'SourceUnit'

ericglau avatar Dec 14 '22 22:12 ericglau

FunctionCall's expression.referencedDeclaration can also reference 'VariableDeclaration', 'ErrorDefinition'

ericglau avatar Dec 15 '22 22:12 ericglau