collection of AST nodes

useEther_5013
aniket-engg 4 years ago committed by Aniket
parent ac818121ad
commit 143ab334f6
  1. 32
      libs/remix-astwalker/src/astWalker.ts

@ -59,10 +59,36 @@ export class AstWalker extends EventEmitter {
} }
} }
normalizeNodes(nodes: AstNode[]): AstNode[] {
// TODO: If any element in nodes is array, extract its members in nodes and delete it
// TODO: Traverse through nodes to check deplicate nodes using id field
return nodes
}
getASTNodeChildren(ast: AstNode): AstNode[] { getASTNodeChildren(ast: AstNode): AstNode[] {
const nodes = ast.nodes || (ast.body && ast.body.statements) || ast.declarations || [] const nodes = ast.nodes // for ContractDefinition
if (ast.body && ast.initializationExpression) { // 'for' loop handling || (ast.body && ast.body.statements) // // for FunctionDefinition
nodes.push(ast.initializationExpression) || ast.members // for StructDefinition, EnumDefinition
|| ast.overrides // for OverrideSpecifier
|| ast.parameters // for ParameterList
|| ast.declarations
|| []
if (ast.body && ast.overrides && ast.parameters && ast.returnParameters && ast.modifiers) { // for FunctionDefinition
nodes.push(ast.overrides)
nodes.push(ast.parameters)
nodes.push(ast.returnParameters)
nodes.push(ast.modifiers)
} else if(ast.overrides && ast.typeName) { // for VariableDeclaration
nodes.push(ast.typeName)
} else if (ast.body && ast.overrides && ast.parameters) { // for ModifierDefinition
nodes.push(ast.overrides)
nodes.push(ast.parameters)
} else if (ast.modifierName && ast.arguments) { // for ModifierInvocation
nodes.push(ast.modifierName)
nodes.push(ast.arguments)
} else if (ast.body && ast.initializationExpression) { // for ForStatement
nodes.push(ast.initializationExpression)
} }
return nodes return nodes
} }

Loading…
Cancel
Save