Skip to main content
Version: Latest(3.11)

SwitchCase 选择分支情况

1. 结构声明

class SwitchCase extends LogicItem {
test?: LogicItem;
consequent: Array<LogicItem>;
}

2. 节点示例

(1) 示例

AST 如下:

{
"concept": "SwitchCase",
"test": {
"concept": "BinaryExpression",
"left": {
"concept": "MemberExpression",
"object": {
"concept": "Identifier",
"namespace": "",
"name": "list"
},
"property": {
"concept": "Identifier",
"namespace": "",
"name": "length"
}
},
"right": {
"concept": "NumericLiteral",
"value": "10",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
},
"operator": "<="
},
"consequent": [
{
"concept": "CallLogic",
"uuid": "08d83151df934c3e904ab8704e14b2ae",
"calleeNamespace": "nasl.logging",
"calleeName": "INFO",
"shortcut": true,
"arguments": [
{
"concept": "Argument",
"keyword": "模板",
"expression": {
"concept": "StringLiteral",
"value": "情况2"
}
}
]
}
]
}

对应的代码如下:

list.length <= 10 => {
nasl::logging::INFO('情况2')
}

(2) else

AST 如下:

{
"concept": "SwitchCase",
"consequent": [
{
"concept": "CallLogic",
"uuid": "11fe6dacbd3f42749c14c272fad6ffbb",
"calleeNamespace": "nasl.logging",
"calleeName": "INFO",
"shortcut": true,
"arguments": [
{
"concept": "Argument",
"keyword": "模板",
"expression": {
"concept": "StringLiteral",
"value": "其它情况"
}
}
]
}
]
}

对应的代码如下:

_ => {
nasl::logging::INFO('其它情况')
}