Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
8cdbed92
Commit
8cdbed92
authored
Oct 31, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
solidity asthelpers, decodeinfo
parent
54581749
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
430 additions
and
0 deletions
+430
-0
astHelper.js
src/solidity/astHelper.js
+64
-0
decodeInfo.js
src/solidity/decodeInfo.js
+353
-0
astWalker.js
src/util/astWalker.js
+13
-0
No files found.
src/solidity/astHelper.js
0 → 100644
View file @
8cdbed92
'use strict'
var
AstWalker
=
require
(
'../util/astWalker'
)
/**
* return all contract definitions of the given @astList
*
* @param {Object} sourcesList - sources list (containing root AST node)
* @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts
*/
function
extractContractsDefinition
(
sourcesList
)
{
var
ret
=
{
contractsIds
:
{},
contractsNames
:
{}
}
var
walker
=
new
AstWalker
()
walker
.
walkAstList
(
sourcesList
,
{
'ContractDefinition'
:
function
(
node
)
{
ret
.
contractsIds
[
node
.
id
]
=
node
ret
.
contractsNames
[
node
.
attributes
.
name
]
=
node
.
id
return
false
}})
return
ret
}
/**
* returns the linearized base contracts of the contract @arg id
*
* @param {Int} id - contract id to resolve
* @param {Map} contracts - all contracts defined in the current context
* @return {Array} - array of base contracts in derived to base order as AST nodes.
*/
function
getLinearizedBaseContracts
(
id
,
contracts
)
{
return
contracts
[
id
].
attributes
.
linearizedBaseContracts
.
map
(
function
(
id
)
{
return
contracts
[
id
]
})
}
/**
* return state var and type definition of the given contract
*
* @param {String} contractName - contract for which state var should be resolved
* @param {Object} sourcesList - sources list (containing root AST node)
* @return {Array} - return an array of AST node of all state variables (including inherited) (this will include all enum/struct declarations)
*/
function
extractStateVariables
(
contractName
,
sourcesList
)
{
var
contracts
=
extractContractsDefinition
(
sourcesList
)
var
id
=
contracts
.
contractsNames
[
contractName
]
if
(
id
)
{
var
stateVar
=
[]
var
baseContracts
=
getLinearizedBaseContracts
(
id
,
contracts
.
contractsIds
)
baseContracts
.
reverse
()
for
(
var
k
in
baseContracts
)
{
var
ctr
=
baseContracts
[
k
]
for
(
var
i
in
ctr
.
children
)
{
stateVar
.
push
(
ctr
.
children
[
i
])
}
}
return
stateVar
}
return
null
}
module
.
exports
=
{
extractStateVariables
:
extractStateVariables
,
extractContractsDefinition
:
extractContractsDefinition
,
getLinearizedBaseContracts
:
getLinearizedBaseContracts
}
src/solidity/decodeInfo.js
0 → 100644
View file @
8cdbed92
This diff is collapsed.
Click to expand it.
src/util/astWalker.js
View file @
8cdbed92
...
@@ -30,6 +30,19 @@ AstWalker.prototype.walk = function (ast, callback) {
...
@@ -30,6 +30,19 @@ AstWalker.prototype.walk = function (ast, callback) {
}
}
}
}
/**
+ * walk the given @astList
+ *
+ * @param {Object} sourcesList - sources list (containing root AST node)
+ * @param {Function} - callback used by AstWalker to compute response
+ */
AstWalker
.
prototype
.
walkAstList
=
function
(
sourcesList
,
callback
)
{
var
walker
=
new
AstWalker
()
for
(
var
k
in
sourcesList
)
{
walker
.
walk
(
sourcesList
[
k
].
AST
,
callback
)
}
}
function
manageCallBack
(
node
,
callback
)
{
function
manageCallBack
(
node
,
callback
)
{
if
(
node
.
name
in
callback
)
{
if
(
node
.
name
in
callback
)
{
return
callback
[
node
.
name
](
node
)
return
callback
[
node
.
name
](
node
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment