feat: add Extra field to store additional AST node metadata #152
+260
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Collect direct calls and anonymous functions in Go parser and store them in the Extra field of Function, Dependency, Type, and Var.
What type of PR is this?
feat
Check the PR title.
(Optional) Translate the PR title into Chinese.
feat:增加 Extra Field 去存储额外的 AST 元信息
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
Extrafield to theDependencyto record whether a func or method is actually invoked viaCallExpr. This information is only added toFunction-typeFunctionCallsandMethodCalls, and toVars-typeDependencies.Extrafield toFunction, and add a fieldAnonymousFunctionsinside it to record the anonymous functions defined in this Function.Extrafield toVar, and include aAnonymousFunctionsfield within it to record the anonymousFunctiondefined in the initializationExprof thisVar.ExtratoType(it's added for symmetry).Compatibility Analysis
Dependency
{ "ModPath": "code.byted.org/middleware/hkong_api", "PkgPath": "code.byted.org/middleware/hkong_api/biz/middleware", "Name": "ReportCall", "File": "router.go", "Line": 17, "StartOffset": 576, "EndOffset": 586 }, { "ModPath": "code.byted.org/middleware/hkong_api", "PkgPath": "code.byted.org/middleware/hkong_api/biz/middleware", "Name": "CheckAcessToken", "File": "router.go", "Line": 17, "StartOffset": 599, "EndOffset": 614, }Extraonly appears in:FunctionCallorMethodCallsof aFunctionDependencyof aVar{ "ModPath": "code.byted.org/middleware/hkong_api", "PkgPath": "code.byted.org/middleware/hkong_api/biz/middleware", "Name": "ReportCall", "File": "router.go", "Line": 17, "StartOffset": 576, "EndOffset": 586 // ``ReportCall`` is not directly called, so no ``Extra`` }, { "ModPath": "code.byted.org/middleware/hkong_api", "PkgPath": "code.byted.org/middleware/hkong_api/biz/middleware", "Name": "CheckAcessToken", "File": "router.go", "Line": 17, "StartOffset": 599, "EndOffset": 614, "Extra": { "FunctionIsCall": true // ``CheckAcessToken`` is directly called, so ``FunctionIsCall": true exists } }Function or Var
- Source Code
Other Language Related
Extrafields here will have no data (the field does not exist)structduring JSON unmarshalling, theExtrafield will be directly ignoredmapduring JSON unmarshalling, theExtrafield will exist in themap, but it will not be affected unless this field is specifically specifiedzh(optional):
(Optional) Which issue(s) this PR fixes:
(optional) The PR that updates user documentation: