CallFunction 调用函数
1. 结构声明
- TS Declaration
- JSON Schema
class CallFunction extends LogicItem {
calleeNamespace: string;
calleeName: string;
shortcut?: boolean;
typeArguments?: Array<TypeAnnotation>;
arguments: Array<Argument>;
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"label": {
"type": "string"
},
"description": {
"type": "string"
},
"folded": {
"type": "boolean"
},
"offsetX": {
"type": "number"
},
"offsetY": {
"type": "number"
},
"typeAnnotation": {
"$ref": "#/definitions/TypeAnnotation"
},
"calleeNamespace": {
"type": "string"
},
"calleeName": {
"type": "string"
},
"shortcut": {
"type": "boolean"
},
"typeArguments": {
"type": "array",
"items": {
"$ref": "#/definitions/TypeAnnotation"
}
},
"arguments": {
"type": "array",
"items": {
"$ref": "#/definitions/Argument"
}
}
},
"required": [
"calleeNamespace",
"calleeName",
"arguments"
],
"additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
"concept": "CallFunction",
"label": "调用逻辑",
"calleeNamespace": "nasl.util",
"calleeName": "Clone",
"arguments": [
{
"concept": "Argument",
"keyword": "obj",
"expression": {
"concept": "Identifier",
"namespace": "",
"name": "student"
}
}
]
}
concept: CallFunction
label: 调用逻辑
calleeNamespace: nasl.util
calleeName: Clone
arguments:
- concept: Argument
keyword: obj
expression:
concept: Identifier
namespace: ""
name: student
对应的代码如下:
- 文本化 NASL
- Natural TS
nasl::util::Clone(student)
nasl.util.Clone(student)
(2) 带 lambda 的入参
AST 如下:
- JSON
- YAML
{
"concept": "CallFunction",
"label": "内置函数",
"calleeNamespace": "nasl.util",
"calleeName": "ListFilter",
"typeArguments": [],
"arguments": [
{
"concept": "Argument",
"keyword": "list",
"expression": {
"concept": "Identifier",
"namespace": "",
"name": "list"
}
},
{
"concept": "Argument",
"keyword": "by",
"expression": {
"concept": "AnonymousFunction",
"params": [
{
"concept": "Param",
"name": "item",
"description": ""
}
],
"body": {
"concept": "BinaryExpression",
"left": {
"concept": "MemberExpression",
"object": {
"concept": "MemberExpression",
"object": {
"concept": "Identifier",
"namespace": "",
"name": "item"
},
"property": {
"concept": "Identifier",
"namespace": "",
"name": "productReport"
}
},
"property": {
"concept": "Identifier",
"namespace": "",
"name": "executed"
}
},
"right": {
"concept": "NullLiteral"
},
"operator": "!="
}
}
}
]
}
concept: CallFunction
label: 内置函数
calleeNamespace: nasl.util
calleeName: ListFilter
typeArguments: []
arguments:
- concept: Argument
keyword: list
expression:
concept: Identifier
namespace: ""
name: list
- concept: Argument
keyword: by
expression:
concept: AnonymousFunction
params:
- concept: Param
name: item
description: ""
body:
concept: BinaryExpression
left:
concept: MemberExpression
object:
concept: MemberExpression
object:
concept: Identifier
namespace: ""
name: item
property:
concept: Identifier
namespace: ""
name: productReport
property:
concept: Identifier
namespace: ""
name: executed
right:
concept: NullLiteral
operator: "!="
对应的代码如下:
- 文本化 NASL
- Natural TS
nasl::util::ListFilter(list, { item: String => item.productReport.executed != null })
nasl.util.ListFilter(list, (item: String) => item.productReport.executed != null)