solc-ast – 硬脂酸盐区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,solc-ast – 硬脂酸盐区块链毕设代写 是一篇很好的国外资料

solc-ast

solc-ast - 硬脂酸盐 solc-ast - 硬脂酸盐 solc-ast - 硬脂酸盐

A tool for exploring the Solidity abstrax syntrax tree as generated by the solc compiler.

Installation

You can install the latest release via pip:

$ pip install py-solc-ast

Or clone the repo and use setuptools:

$ python setup.py install

Usage

First, use py-solc-x to compile your contracts to the standard JSON output format.

>>> import json >>> import solcx >>> input_json = json.load(open('input.json')) >>> output_json = solcx.compile_standard(input_json)

Next, import solcast and initialize using from_standard_output_json or from_standard_output. This returns a list of SourceUnit objects, which each represent the base AST node in a Solidity source file.

>>> import solcast >>> nodes = solcast.from_standard_output(output_json) >>> nodes [<SourceUnit iterable 'contracts/Token.sol'>, <SourceUnit iterable 'contracts/SafeMath.sol'>]

You can also generate a single SourceUnit directly from that source’s AST:

>>> import solcast >>> node = solcast.from_ast(output_json["sources"]["contracts/Token.sol"]["ast"]) >>> node <SourceUnit iterable 'contracts/Token.sol'>

Interacting with Nodes

Each node has the following attributes:

>>> node <FunctionDefinition iterable 'mul'>  >>> node.depth  # Number of nodes between this node and the SourceUnit 2  >>> node.offset  # Absolute source offsets as a (start, stop) tuple (1693, 2151)  >>> node.contract_id  # Contract ID as given by the standard compiler JSON 2  >>> node.fields  # List of fields for this node ['baseNodeType', 'documentation', 'id', 'implemented', 'kind', 'modifiers', 'name', 'nodeType', 'nodes', 'parameters', 'returnParameters', 'scope', 'src', 'stateMutability', 'superFunction', 'visibility']

Fields mostly follow the expected AST grammar. One notable difference: Block nodes are omitted and the body of each Block is available within it’s parent as the attribute nodes. Nodes containing a body are iterable and can be accessed with list-like syntax. Additionally, any child node with a name field is accessible using dict-like syntax.

The following additional fields are also available:

  • Most nodes have a baseNodeType field as defined in grammar.py
  • ContractDefinition nodes have dependencies and libraries fields that point to related ContractDefition nodes

Some Examples:

>>> source_node <SourceUnit iterable 'contracts/math/SafeMath.sol'>  >>> source_node.keys() ['absolutePath', 'children', 'contract_id', 'depth', 'exportedSymbols', 'id', 'is_child_of', 'is_parent_of', 'keys', 'nodeType', 'nodes', 'offset', 'parent', 'parents', 'src']  >>> source_node.nodes [<PragmaDirective object>, <ContractDefinition iterable 'SafeMath'>]  >>> source_node[1] <ContractDefinition iterable 'SafeMath'>  >>> source_node['SafeMath'] <ContractDefinition iterable 'SafeMath'>  >>> source_node['SafeMath'].keys() ['baseContracts', 'children', 'contractDependencies', 'contractKind', 'contract_id', 'dependencies', 'depth', 'documentation', 'fullyImplemented', 'id', 'is_child_of', 'is_parent_of', 'keys', 'libraries', 'linearizedBaseContracts', 'name', 'nodeType', 'nodes', 'offset', 'parent', 'parents', 'scope', 'src']  >>> source_node['SafeMath'].nodes [<FunctionDefinition iterable 'add'>, <FunctionDefinition iterable 'sub'>, <FunctionDefinition iterable 'mul'>, <FunctionDefinition iterable 'div'>, <FunctionDefinition iterable 'mod'>]  >>> source_node['SafeMath']['mul'] <FunctionDefinition iterable 'mul'>  >>> source_node['SafeMath']['mul'] [<IfStatement object>, <VariableDeclarationStatement object>, <FunctionCall object>, <Return object>]

Exploring the Tree

The Node.children() method is used to search and filter through child nodes of a given node. It takes any of the following keyword arguments:

  • depth: Number of levels of children to traverse. 0 returns only this node.
  • include_self: Includes this node in the results.
  • include_parents: Includes nodes that match in the results, when they also have child nodes that match.
  • include_children: If True, as soon as a match is found it’s children will not be included in the search.
  • required_offset: Only match nodes with a source offset that contains this offset.
  • offset_limits: Only match nodes when their source offset is contained inside this source offset.
  • filters: Dictionary of {'attribute': "value"} that children must match. Can also be given as a list of dicts, children that match any of the dicts will be returned.
  • exclude_filter: Dictionary of {'attribute': "value"} that children cannot match.
>>> node = s['Token']['transfer'] >>> node.children(     include_children=False,     filters={'nodeType': "FunctionCall", "expression.name": "require"} ) [<FunctionCall>]

Node.parent() and Node.parents() are used to travel back up the tree. They take the following arguments:

  • depth: Depth limit. If given as a negative value, it will be subtracted from this object’s depth.
  • filters: Dictionary of {'attribute': "value"} that parents must match.

Node.parent() returns one result, Node.parents() returns a list of matches.

>>> node.parents() [<ContractDefinition iterable 'Token'>, <SourceUnit iterable object 'contracts/Token.sol'>]

Tests

To run the test suite:

$ tox

Development

Comments, questions, criticisms and pull requests are welcomed! Feel free to open an issue if you encounter a problem or would like to suggest a new feature.

License

This project is licensed under the MIT license.


solc ast

一种工具,用于探索solc编译器生成的稳固的abstrax syntrax树。

您可以通过pip安装最新版本:

安装

或克隆repo并使用setuptools:

$ pip install py-solc-ast

首先,使用py-solc-x将合同编译为标准的JSON输出格式。

$ python setup.py install

用法

接下来,使用from u standard u output u json或from u standard u output导入solcast并初始化。这将返回SourceUnit对象的列表,每个对象表示Solidity源文件中的基本AST节点。

>>> import json >>> import solcx >>> input_json = json.load(open('input.json')) >>> output_json = solcx.compile_standard(input_json)

您还可以直接从该源的AST生成单个SourceUnit:

>>> import solcast >>> nodes = solcast.from_standard_output(output_json) >>> nodes [<SourceUnit iterable 'contracts/Token.sol'>, <SourceUnit iterable 'contracts/SafeMath.sol'>]

每个节点都有以下属性:

>>> import solcast >>> node = solcast.from_ast(output_json["sources"]["contracts/Token.sol"]["ast"]) >>> node <SourceUnit iterable 'contracts/Token.sol'>

与节点交互

字段主要遵循预期的AST语法。一个显著的区别是:省略了块节点,每个块的主体在其父块中可用作属性节点。包含主体的节点是iterable的,可以使用类似列表的语法进行访问。此外,任何具有名称字段的子节点都可以使用类似dict的语法进行访问。

>>> node <FunctionDefinition iterable 'mul'>  >>> node.depth  # Number of nodes between this node and the SourceUnit 2  >>> node.offset  # Absolute source offsets as a (start, stop) tuple (1693, 2151)  >>> node.contract_id  # Contract ID as given by the standard compiler JSON 2  >>> node.fields  # List of fields for this node ['baseNodeType', 'documentation', 'id', 'implemented', 'kind', 'modifiers', 'name', 'nodeType', 'nodes', 'parameters', 'returnParameters', 'scope', 'src', 'stateMutability', 'superFunction', 'visibility']

以下附加字段也可用:

一些示例:

  • 大多数节点都具有中定义的baseNodeType字段语法.py
  • ContractDefinition节点具有指向相关的ContractDefinition节点

节点.子节点()方法用于搜索和筛选给定节点的子节点。它接受以下任何关键字参数:

>>> source_node <SourceUnit iterable 'contracts/math/SafeMath.sol'>  >>> source_node.keys() ['absolutePath', 'children', 'contract_id', 'depth', 'exportedSymbols', 'id', 'is_child_of', 'is_parent_of', 'keys', 'nodeType', 'nodes', 'offset', 'parent', 'parents', 'src']  >>> source_node.nodes [<PragmaDirective object>, <ContractDefinition iterable 'SafeMath'>]  >>> source_node[1] <ContractDefinition iterable 'SafeMath'>  >>> source_node['SafeMath'] <ContractDefinition iterable 'SafeMath'>  >>> source_node['SafeMath'].keys() ['baseContracts', 'children', 'contractDependencies', 'contractKind', 'contract_id', 'dependencies', 'depth', 'documentation', 'fullyImplemented', 'id', 'is_child_of', 'is_parent_of', 'keys', 'libraries', 'linearizedBaseContracts', 'name', 'nodeType', 'nodes', 'offset', 'parent', 'parents', 'scope', 'src']  >>> source_node['SafeMath'].nodes [<FunctionDefinition iterable 'add'>, <FunctionDefinition iterable 'sub'>, <FunctionDefinition iterable 'mul'>, <FunctionDefinition iterable 'div'>, <FunctionDefinition iterable 'mod'>]  >>> source_node['SafeMath']['mul'] <FunctionDefinition iterable 'mul'>  >>> source_node['SafeMath']['mul'] [<IfStatement object>, <VariableDeclarationStatement object>, <FunctionCall object>, <Return object>]

探索树

节点.父级()和节点.父节点()用于返回树上。它们采用以下参数:

  • 深度:要遍历的子级的级别数。0仅返回此节点。
  • 包含自身:在结果中包含此节点。
  • 包含父节点:包含结果中匹配的节点,同时这些节点还有匹配的子节点。
  • 包含子项:如果为True,则一旦找到匹配项,其子项将不包含在搜索中。
  • 必需的u偏移:仅匹配具有包含此偏移的源偏移的节点。
  • 偏移量限制:仅当节点的源偏移量包含在此源偏移量内时才匹配节点。
  • 筛选器:子级必须匹配的{attribute’:“value”}字典。也可以作为dict列表给出,匹配任何dict的子级都将被返回。
  • 排除子级无法匹配的{attribute’:“value”}字典。
>>> node = s['Token']['transfer'] >>> node.children(     include_children=False,     filters={'nodeType': "FunctionCall", "expression.name": "require"} ) [<FunctionCall>]

节点.父级()返回一个结果,节点.父节点()返回匹配项列表。

  • 深度:深度限制。如果给定为负值,它将从该对象的深度中减去。
  • 筛选器:父级必须匹配的{attribute’:“value”}字典。你知道吗

要运行测试套件:

>>> node.parents() [<ContractDefinition iterable 'Token'>, <SourceUnit iterable object 'contracts/Token.sol'>]

测试

欢迎评论、问题、批评和请求!如果您遇到问题或想建议新功能,请随时打开一个问题。

$ tox

开发

这个项目是根据麻省理工学院的许可证授权的。

许可证

This project is licensed under the MIT license.

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/19488.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » solc-ast – 硬脂酸盐区块链毕设代写

提供最优质的资源集合

立即查看 了解详情