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
d5548b62
Commit
d5548b62
authored
Feb 25, 2020
by
aniket-engg
Committed by
Aniket
Mar 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
isFunctionDefinition removed
parent
de6e96b2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
43 deletions
+51
-43
abstractAstView.ts
...analyzer/src/solidity-analyzer/modules/abstractAstView.ts
+7
-6
staticAnalysisCommon.ts
...zer/src/solidity-analyzer/modules/staticAnalysisCommon.ts
+21
-27
types.ts
remix-analyzer/src/types.ts
+13
-0
staticAnalysisCommon-test.ts
remix-analyzer/test/analysis/staticAnalysisCommon-test.ts
+10
-10
No files found.
remix-analyzer/src/solidity-analyzer/modules/abstractAstView.ts
View file @
d5548b62
import
{
isContractDefinition
,
getStateVariableDeclarationsFormContractNode
,
isInheritanceSpecifier
,
getInheritsFromName
,
is
FunctionDefinition
,
is
ModifierDefinition
,
isModifierInvocation
,
getContractName
,
getInheritsFromName
,
isModifierDefinition
,
isModifierInvocation
,
getContractName
,
getFunctionOrModifierDefinitionParameterPart
,
getType
,
getDeclaredVariableName
,
isVariableDeclaration
,
getFunction
OrModifier
DefinitionReturnParameterPart
}
from
'./staticAnalysisCommon'
getFunctionDefinitionReturnParameterPart
}
from
'./staticAnalysisCommon'
import
{
AstWalker
}
from
'remix-astwalker'
import
{
CommonAstNode
}
from
'types'
export
default
class
abstractAstView
{
contracts
=
[]
...
...
@@ -48,8 +49,8 @@ export default class abstractAstView {
*/
build_visit
(
relevantNodeFilter
)
{
var
that
=
this
return
function
(
node
)
{
if
(
isContractDefinition
(
node
)
)
{
return
function
(
node
:
CommonAstNode
)
{
if
(
node
.
nodeType
===
"ContractDefinition"
)
{
that
.
setCurrentContract
(
that
,
{
node
:
node
,
functions
:
[],
...
...
@@ -62,7 +63,7 @@ export default class abstractAstView {
const
currentContract
=
that
.
getCurrentContract
(
that
)
const
inheritsFromName
=
getInheritsFromName
(
node
)
currentContract
.
inheritsFrom
.
push
(
inheritsFromName
)
}
else
if
(
isFunctionDefinition
(
node
)
)
{
}
else
if
(
node
.
nodeType
===
"FunctionDefinition"
)
{
that
.
setCurrentFunction
(
that
,
{
node
:
node
,
relevantNodes
:
[],
...
...
@@ -163,7 +164,7 @@ export default class abstractAstView {
}
private
getReturnParameters
(
funcNode
)
{
return
this
.
getLocalVariables
(
getFunction
OrModifier
DefinitionReturnParameterPart
(
funcNode
)).
map
((
n
)
=>
{
return
this
.
getLocalVariables
(
getFunctionDefinitionReturnParameterPart
(
funcNode
)).
map
((
n
)
=>
{
return
{
type
:
getType
(
n
),
name
:
getDeclaredVariableName
(
n
)
...
...
remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts
View file @
d5548b62
'use strict'
import
{
FunctionDefinitionAstNode
,
ModifierDefinitionAstNode
,
ParameterListAstNode
}
from
"types"
const
remixLib
=
require
(
'remix-lib'
)
const
util
=
remixLib
.
util
...
...
@@ -244,9 +246,9 @@ function getContractName (contract) {
* @funcDef {ASTNode} Function Definition node
* @return {string} name of a function defined
*/
function
getFunctionDefinitionName
(
funcDef
)
{
if
(
!
isFunctionDefinition
(
funcDef
))
throw
new
Error
(
'staticAnalysisCommon.js: not an functionDefinition Node'
)
return
funcDef
.
attributes
.
name
function
getFunctionDefinitionName
(
funcDef
:
FunctionDefinitionAstNode
):
string
{
//
if (!isFunctionDefinition(funcDef)) throw new Error('staticAnalysisCommon.js: not an functionDefinition Node')
return
funcDef
.
name
}
/**
...
...
@@ -308,9 +310,9 @@ function getStateVariableDeclarationsFormContractNode (contractNode) {
* @funcNode {ASTNode} Contract Definition node
* @return {parameterlist node} parameterlist node
*/
function
getFunctionOrModifierDefinitionParameterPart
(
funcNode
)
{
if
(
!
isFunctionDefinition
(
funcNode
)
&&
!
isModifierDefinition
(
funcNode
))
throw
new
Error
(
'staticAnalysisCommon.js: not a function definition'
)
return
funcNode
.
children
[
0
]
function
getFunctionOrModifierDefinitionParameterPart
(
funcNode
:
FunctionDefinitionAstNode
|
ModifierDefinitionAstNode
):
ParameterListAstNode
{
//
if (!isFunctionDefinition(funcNode) && !isModifierDefinition(funcNode)) throw new Error('staticAnalysisCommon.js: not a function definition')
return
funcNode
.
parameters
}
/**
...
...
@@ -320,9 +322,8 @@ function getFunctionOrModifierDefinitionParameterPart (funcNode) {
* @funcNode {ASTNode} Contract Definition node
* @return {parameterlist node} parameterlist node
*/
function
getFunctionOrModifierDefinitionReturnParameterPart
(
funcNode
)
{
if
(
!
isFunctionDefinition
(
funcNode
)
&&
!
isModifierDefinition
(
funcNode
))
throw
new
Error
(
'staticAnalysisCommon.js: not a function definition'
)
return
funcNode
.
children
[
1
]
function
getFunctionDefinitionReturnParameterPart
(
funcNode
:
FunctionDefinitionAstNode
):
ParameterListAstNode
{
return
funcNode
.
returnParameters
}
/**
...
...
@@ -424,9 +425,9 @@ function getLoopBlockStartIndex (node) {
// #################### Trivial Node Identification
function
isFunctionDefinition
(
node
)
{
return
nodeType
(
node
,
exactMatch
(
nodeTypes
.
FUNCTIONDEFINITION
))
}
//
function isFunctionDefinition (node) {
//
return nodeType(node, exactMatch(nodeTypes.FUNCTIONDEFINITION))
//
}
function
isStatement
(
node
)
{
return
nodeType
(
node
,
'Statement$'
)
||
isBlock
(
node
)
||
isReturn
(
node
)
...
...
@@ -664,11 +665,8 @@ function isStateVariable (name, stateVariables) {
* @node {ASTNode} some AstNode
* @return {bool}
*/
function
isConstantFunction
(
node
)
{
return
isFunctionDefinition
(
node
)
&&
(
node
.
attributes
.
stateMutability
===
'view'
||
node
.
attributes
.
stateMutability
===
'pure'
)
function
isConstantFunction
(
node
:
FunctionDefinitionAstNode
):
boolean
{
return
node
.
stateMutability
===
'view'
||
node
.
stateMutability
===
'pure'
}
/**
...
...
@@ -676,10 +674,8 @@ function isConstantFunction (node) {
* @node {ASTNode} some AstNode
* @return {bool}
*/
function
isPayableFunction
(
node
)
{
return
isFunctionDefinition
(
node
)
&&
(
node
.
attributes
.
stateMutability
===
'payable'
)
function
isPayableFunction
(
node
:
FunctionDefinitionAstNode
):
boolean
{
return
node
.
stateMutability
===
'payable'
}
/**
...
...
@@ -687,10 +683,8 @@ function isPayableFunction (node) {
* @node {ASTNode} some AstNode
* @return {bool}
*/
function
isConstructor
(
node
)
{
return
isFunctionDefinition
(
node
)
&&
(
node
.
attributes
.
isConstructor
===
true
)
function
isConstructor
(
node
:
FunctionDefinitionAstNode
):
boolean
{
return
node
.
kind
===
"constructor"
}
/**
...
...
@@ -1125,7 +1119,7 @@ export {
getFullQuallyfiedFuncDefinitionIdent
,
getStateVariableDeclarationsFormContractNode
,
getFunctionOrModifierDefinitionParameterPart
,
getFunction
OrModifier
DefinitionReturnParameterPart
,
getFunctionDefinitionReturnParameterPart
,
getUnAssignedTopLevelBinOps
,
getLoopBlockStartIndex
,
...
...
@@ -1179,7 +1173,7 @@ export {
// #################### Trivial Node Identification
isDeleteUnaryOperation
,
isFunctionDefinition
,
//
isFunctionDefinition,
isModifierDefinition
,
isInheritanceSpecifier
,
isModifierInvocation
,
...
...
remix-analyzer/src/types.ts
View file @
d5548b62
...
...
@@ -542,6 +542,13 @@ export interface StructuredDocumentationAstNode {
text
:
string
}
export
interface
CommonAstNode
{
id
:
number
nodeType
:
string
src
:
string
[
x
:
string
]:
any
}
/////////////////////////////////////////////////////////
///////////// YUL AST Nodes /////////////////////////////
...
...
@@ -580,6 +587,12 @@ export interface YulBlockAstNode {
src
:
string
statements
:
Array
<
YulVariableDeclarationAstNode
>
}
export
interface
CommonYulAstNode
{
nodeType
:
string
src
:
string
[
x
:
string
]:
any
}
///////////
...
...
remix-analyzer/test/analysis/staticAnalysisCommon-test.ts
View file @
d5548b62
...
...
@@ -306,16 +306,16 @@ test('staticAnalysisCommon.getLoopBlockStartIndex', function (t) {
// #################### Trivial Node Identification
test
(
'staticAnalysisCommon.isFunctionDefinition'
,
function
(
t
)
{
t
.
plan
(
3
)
const
node1
=
{
name
:
'FunctionDefinition'
}
const
node2
=
{
name
:
'MemberAccess'
}
const
node3
=
{
name
:
'FunctionDefinitionBLABLA'
}
t
.
ok
(
common
.
isFunctionDefinition
(
node1
),
'is exact match should work'
)
t
.
notOk
(
common
.
isFunctionDefinition
(
node2
),
'different node should not work'
)
t
.
notOk
(
common
.
isFunctionDefinition
(
node3
),
'substring should not work'
)
})
//
test('staticAnalysisCommon.isFunctionDefinition', function (t) {
//
t.plan(3)
//
const node1 = { name: 'FunctionDefinition' }
//
const node2 = { name: 'MemberAccess' }
//
const node3 = { name: 'FunctionDefinitionBLABLA' }
//
t.ok(common.isFunctionDefinition(node1), 'is exact match should work')
//
t.notOk(common.isFunctionDefinition(node2), 'different node should not work')
//
t.notOk(common.isFunctionDefinition(node3), 'substring should not work')
//
})
test
(
'staticAnalysisCommon.isModifierDefinition'
,
function
(
t
)
{
t
.
plan
(
3
)
...
...
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