arkanalyzer 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/arkanalyzer.json +8 -0
- package/docs/IR2ts-stmt.md +81 -0
- package/docs/IR2ts.md +82 -0
- package/lib/Config.d.ts +29 -1
- package/lib/Config.d.ts.map +1 -1
- package/lib/Config.js +44 -11
- package/lib/Scene.d.ts +152 -9
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +233 -66
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +2 -1
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/AbstractAnalysis.js +14 -7
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +2 -4
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +2 -3
- package/lib/callgraph/common/Statistics.js +1 -1
- package/lib/callgraph/model/BaseGraph.js +2 -2
- package/lib/callgraph/model/CallGraph.d.ts +3 -2
- package/lib/callgraph/model/CallGraph.d.ts.map +1 -1
- package/lib/callgraph/model/CallGraph.js +23 -14
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +2 -2
- package/lib/callgraph/model/builder/CallGraphBuilder.js +3 -3
- package/lib/callgraph/pointerAnalysis/Context.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Context.js +0 -1
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +36 -9
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +130 -37
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +34 -5
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +479 -126
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +6 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +107 -45
- package/lib/callgraph/pointerAnalysis/PtsDS.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PtsDS.js +0 -2
- package/lib/core/base/Constant.d.ts +37 -5
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +58 -8
- package/lib/core/base/Expr.d.ts +98 -13
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +295 -127
- package/lib/core/base/Local.d.ts +70 -5
- package/lib/core/base/Local.d.ts.map +1 -1
- package/lib/core/base/Local.js +77 -4
- package/lib/core/base/Ref.d.ts +79 -5
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +143 -38
- package/lib/core/base/Stmt.d.ts +126 -12
- package/lib/core/base/Stmt.d.ts.map +1 -1
- package/lib/core/base/Stmt.js +135 -28
- package/lib/core/base/Type.d.ts +11 -2
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +47 -42
- package/lib/core/base/Value.d.ts +24 -2
- package/lib/core/base/Value.d.ts.map +1 -1
- package/lib/core/common/ArkError.d.ts +15 -0
- package/lib/core/common/ArkError.d.ts.map +1 -0
- package/lib/core/common/ArkError.js +28 -0
- package/lib/core/common/ArkIRTransformer.d.ts +12 -5
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +90 -45
- package/lib/core/common/BodyBuilder.d.ts +2 -0
- package/lib/core/common/BodyBuilder.d.ts.map +1 -1
- package/lib/core/common/BodyBuilder.js +5 -2
- package/lib/core/common/Builtin.js +1 -1
- package/lib/core/common/CfgBuilder.d.ts +12 -7
- package/lib/core/common/CfgBuilder.d.ts.map +1 -1
- package/lib/core/common/CfgBuilder.js +336 -140
- package/lib/core/common/Const.d.ts +15 -10
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +18 -11
- package/lib/core/common/DummyMainCreater.d.ts +5 -4
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +43 -28
- package/lib/core/common/EtsConst.d.ts +1 -0
- package/lib/core/common/EtsConst.d.ts.map +1 -1
- package/lib/core/common/EtsConst.js +2 -1
- package/lib/core/common/ExprUseReplacer.js +8 -8
- package/lib/core/common/IRUtils.d.ts +7 -0
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +34 -2
- package/lib/core/common/ModelUtils.d.ts +1 -0
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +39 -36
- package/lib/core/common/RefUseReplacer.js +3 -3
- package/lib/core/common/StmtUseReplacer.js +4 -4
- package/lib/core/common/TSConst.d.ts +10 -3
- package/lib/core/common/TSConst.d.ts.map +1 -1
- package/lib/core/common/TSConst.js +11 -4
- package/lib/core/common/TypeInference.d.ts +8 -2
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +222 -90
- package/lib/core/common/ValueUtil.d.ts +0 -4
- package/lib/core/common/ValueUtil.d.ts.map +1 -1
- package/lib/core/common/ValueUtil.js +10 -27
- package/lib/core/common/VisibleValue.js +1 -1
- package/lib/core/dataflow/DataflowProblem.d.ts +1 -0
- package/lib/core/dataflow/DataflowProblem.d.ts.map +1 -1
- package/lib/core/dataflow/DataflowProblem.js +4 -4
- package/lib/core/dataflow/DataflowSolver.d.ts +20 -16
- package/lib/core/dataflow/DataflowSolver.d.ts.map +1 -1
- package/lib/core/dataflow/DataflowSolver.js +67 -78
- package/lib/core/dataflow/TiantAnalysis.d.ts +1 -0
- package/lib/core/dataflow/TiantAnalysis.d.ts.map +1 -1
- package/lib/core/dataflow/TiantAnalysis.js +42 -28
- package/lib/core/dataflow/UndefinedVariable.d.ts +15 -1
- package/lib/core/dataflow/UndefinedVariable.d.ts.map +1 -1
- package/lib/core/dataflow/UndefinedVariable.js +122 -76
- package/lib/core/dataflow/Util.d.ts +5 -1
- package/lib/core/dataflow/Util.d.ts.map +1 -1
- package/lib/core/dataflow/Util.js +43 -22
- package/lib/core/graph/BasicBlock.d.ts +72 -0
- package/lib/core/graph/BasicBlock.d.ts.map +1 -1
- package/lib/core/graph/BasicBlock.js +165 -3
- package/lib/core/graph/Cfg.d.ts +30 -1
- package/lib/core/graph/Cfg.d.ts.map +1 -1
- package/lib/core/graph/Cfg.js +131 -11
- package/lib/core/graph/DominanceFinder.js +7 -7
- package/lib/core/graph/DominanceTree.js +4 -4
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +6 -5
- package/lib/core/model/ArkBaseModel.d.ts +59 -0
- package/lib/core/model/ArkBaseModel.d.ts.map +1 -0
- package/lib/core/model/ArkBaseModel.js +271 -0
- package/lib/core/model/ArkBody.d.ts +3 -9
- package/lib/core/model/ArkBody.d.ts.map +1 -1
- package/lib/core/model/ArkBody.js +3 -14
- package/lib/core/model/ArkClass.d.ts +107 -13
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +152 -54
- package/lib/core/model/ArkExport.d.ts +8 -7
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +16 -18
- package/lib/core/model/ArkField.d.ts +16 -13
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +18 -62
- package/lib/core/model/ArkFile.d.ts +42 -0
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +58 -0
- package/lib/core/model/ArkImport.d.ts +9 -7
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +11 -12
- package/lib/core/model/ArkMetadata.d.ts +20 -0
- package/lib/core/model/ArkMetadata.d.ts.map +1 -0
- package/lib/core/model/ArkMetadata.js +44 -0
- package/lib/core/model/ArkMethod.d.ts +195 -17
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +363 -46
- package/lib/core/model/ArkNamespace.d.ts +6 -8
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +16 -20
- package/lib/core/model/ArkSignature.d.ts +41 -0
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +76 -19
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +60 -49
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkExportBuilder.js +12 -6
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.js +13 -9
- package/lib/core/model/builder/ArkFileBuilder.js +1 -3
- package/lib/core/model/builder/ArkImportBuilder.d.ts +2 -1
- package/lib/core/model/builder/ArkImportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkImportBuilder.js +16 -13
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +3 -1
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +105 -45
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +4 -5
- package/lib/core/model/builder/builderUtils.d.ts +2 -1
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +63 -43
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -3
- package/lib/save/ArkStream.js +1 -1
- package/lib/save/DotPrinter.d.ts.map +1 -1
- package/lib/save/DotPrinter.js +1 -15
- package/lib/save/GraphPrinter.d.ts.map +1 -1
- package/lib/save/GraphPrinter.js +4 -2
- package/lib/save/JsonPrinter.js +5 -5
- package/lib/save/ViewTreePrinter.d.ts +16 -0
- package/lib/save/ViewTreePrinter.d.ts.map +1 -0
- package/lib/save/ViewTreePrinter.js +130 -0
- package/lib/save/source/SourceBase.d.ts +2 -2
- package/lib/save/source/SourceBase.d.ts.map +1 -1
- package/lib/save/source/SourceBase.js +6 -13
- package/lib/save/source/SourceBody.d.ts.map +1 -1
- package/lib/save/source/SourceBody.js +27 -14
- package/lib/save/source/SourceClass.d.ts.map +1 -1
- package/lib/save/source/SourceClass.js +12 -8
- package/lib/save/source/SourceField.d.ts.map +1 -1
- package/lib/save/source/SourceField.js +6 -2
- package/lib/save/source/SourceMethod.d.ts.map +1 -1
- package/lib/save/source/SourceMethod.js +10 -3
- package/lib/save/source/SourceModule.d.ts.map +1 -1
- package/lib/save/source/SourceModule.js +16 -10
- package/lib/save/source/SourceNamespace.d.ts.map +1 -1
- package/lib/save/source/SourceNamespace.js +4 -0
- package/lib/save/source/SourceStmt.d.ts +1 -1
- package/lib/save/source/SourceStmt.d.ts.map +1 -1
- package/lib/save/source/SourceStmt.js +37 -25
- package/lib/save/source/SourceTransformer.d.ts +6 -0
- package/lib/save/source/SourceTransformer.d.ts.map +1 -1
- package/lib/save/source/SourceTransformer.js +82 -51
- package/lib/save/source/SourceUtils.d.ts.map +1 -1
- package/lib/save/source/SourceUtils.js +12 -11
- package/lib/transformer/StaticSingleAssignmentFormer.js +3 -3
- package/lib/utils/CfgStructualAnalysis.d.ts +1 -0
- package/lib/utils/CfgStructualAnalysis.d.ts.map +1 -1
- package/lib/utils/CfgStructualAnalysis.js +103 -72
- package/lib/utils/callGraphUtils.d.ts.map +1 -1
- package/lib/utils/callGraphUtils.js +7 -10
- package/lib/utils/crypto_utils.d.ts +6 -0
- package/lib/utils/crypto_utils.d.ts.map +1 -0
- package/lib/utils/crypto_utils.js +57 -0
- package/lib/utils/entryMethodUtils.d.ts.map +1 -1
- package/lib/utils/entryMethodUtils.js +27 -26
- package/lib/utils/getAllFiles.d.ts +1 -1
- package/lib/utils/getAllFiles.d.ts.map +1 -1
- package/lib/utils/getAllFiles.js +4 -5
- package/lib/utils/logger.js +2 -2
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkFieldBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkFieldBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"ArkFieldBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkFieldBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAUzC,MAAM,MAAM,YAAY,GAAG,EAAE,CAAC,mBAAmB,GAAG,EAAE,CAAC,kBAAkB,CAAC;AAE1E,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,EAAE,CAAC,mBAAmB,GAAG,EAAE,CAAC,kBAAkB,GAAG,EAAE,CAAC,2BAA2B,GACxH,EAAE,CAAC,gBAAgB,GAAG,EAAE,CAAC,iBAAiB,GAAG,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,QAAQ,GAAG,QAAQ,CAuDpH;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,EAAE,CAAC,yBAAyB,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,QAAQ,QAmB1H;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,EAAE,CAAC,sBAAsB,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,QAiCtH"}
|
|
@@ -48,6 +48,8 @@ const builderUtils_1 = require("./builderUtils");
|
|
|
48
48
|
const ArkSignature_1 = require("../ArkSignature");
|
|
49
49
|
const Type_1 = require("../../base/Type");
|
|
50
50
|
const Position_1 = require("../../base/Position");
|
|
51
|
+
const ArkBaseModel_1 = require("../ArkBaseModel");
|
|
52
|
+
const IRUtils_1 = require("../../common/IRUtils");
|
|
51
53
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ArkFieldBuilder');
|
|
52
54
|
function buildProperty2ArkField(member, sourceFile, cls) {
|
|
53
55
|
let field = new ArkField_1.ArkField();
|
|
@@ -73,23 +75,22 @@ function buildProperty2ArkField(member, sourceFile, cls) {
|
|
|
73
75
|
else if (member.name && ohos_typescript_1.default.isPrivateIdentifier(member.name)) {
|
|
74
76
|
let propertyName = member.name.text;
|
|
75
77
|
fieldName = propertyName.substring(1);
|
|
76
|
-
field.addModifier(
|
|
78
|
+
field.addModifier(ArkBaseModel_1.ModifierType.PRIVATE);
|
|
77
79
|
}
|
|
78
80
|
else {
|
|
79
81
|
logger.warn("Other type of property name found!");
|
|
80
82
|
}
|
|
81
83
|
if ((ohos_typescript_1.default.isPropertyDeclaration(member) || ohos_typescript_1.default.isPropertySignature(member)) && member.modifiers) {
|
|
82
|
-
let modifiers = (0, builderUtils_1.buildModifiers)(member
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
84
|
+
let modifiers = (0, builderUtils_1.buildModifiers)(member);
|
|
85
|
+
field.addModifier(modifiers);
|
|
86
|
+
field.setDecorators((0, builderUtils_1.buildDecorators)(member, sourceFile));
|
|
86
87
|
}
|
|
87
88
|
let fieldType = Type_1.UnknownType.getInstance();
|
|
88
89
|
if ((ohos_typescript_1.default.isPropertyDeclaration(member) || ohos_typescript_1.default.isPropertySignature(member)) && member.type) {
|
|
89
90
|
fieldType = (0, builderUtils_1.buildGenericType)((0, builderUtils_1.tsNode2Type)(member.type, sourceFile, cls), field);
|
|
90
91
|
}
|
|
91
92
|
if (ohos_typescript_1.default.isEnumMember(member)) {
|
|
92
|
-
field.addModifier(
|
|
93
|
+
field.addModifier(ArkBaseModel_1.ModifierType.STATIC);
|
|
93
94
|
fieldType = new Type_1.ClassType(cls.getSignature());
|
|
94
95
|
}
|
|
95
96
|
const fieldSignature = new ArkSignature_1.FieldSignature(fieldName, cls.getSignature(), fieldType, field.isStatic());
|
|
@@ -100,6 +101,7 @@ function buildProperty2ArkField(member, sourceFile, cls) {
|
|
|
100
101
|
if (ohos_typescript_1.default.isPropertyDeclaration(member) && member.exclamationToken) {
|
|
101
102
|
field.setExclamationToken(true);
|
|
102
103
|
}
|
|
104
|
+
IRUtils_1.IRUtils.setLeadingComments(field, member, sourceFile, cls.getDeclaringArkFile().getScene().getOptions());
|
|
103
105
|
cls.addField(field);
|
|
104
106
|
return field;
|
|
105
107
|
}
|
|
@@ -111,14 +113,14 @@ function buildIndexSignature2ArkField(member, sourceFile, cls) {
|
|
|
111
113
|
field.setDeclaringArkClass(cls);
|
|
112
114
|
field.setOriginPosition(Position_1.LineColPosition.buildFromNode(member, sourceFile));
|
|
113
115
|
if (member.modifiers) {
|
|
114
|
-
(0, builderUtils_1.buildModifiers)(member
|
|
115
|
-
|
|
116
|
-
});
|
|
116
|
+
let modifier = (0, builderUtils_1.buildModifiers)(member);
|
|
117
|
+
field.addModifier(modifier);
|
|
117
118
|
}
|
|
118
119
|
const fieldName = '[' + member.parameters[0].getText(sourceFile) + ']';
|
|
119
120
|
const fieldType = (0, builderUtils_1.buildGenericType)((0, builderUtils_1.tsNode2Type)(member.type, sourceFile, field), field);
|
|
120
121
|
const fieldSignature = new ArkSignature_1.FieldSignature(fieldName, cls.getSignature(), fieldType, true);
|
|
121
122
|
field.setSignature(fieldSignature);
|
|
123
|
+
IRUtils_1.IRUtils.setLeadingComments(field, member, sourceFile, cls.getDeclaringArkFile().getScene().getOptions());
|
|
122
124
|
cls.addField(field);
|
|
123
125
|
}
|
|
124
126
|
exports.buildIndexSignature2ArkField = buildIndexSignature2ArkField;
|
|
@@ -184,6 +186,8 @@ function mapSyntaxKindToFieldOriginType(syntaxKind) {
|
|
|
184
186
|
case ohos_typescript_1.default.SyntaxKind.GetAccessor:
|
|
185
187
|
fieldOriginType = ArkField_1.FieldCategory.GET_ACCESSOR;
|
|
186
188
|
break;
|
|
189
|
+
default:
|
|
190
|
+
;
|
|
187
191
|
}
|
|
188
192
|
return fieldOriginType;
|
|
189
193
|
}
|
|
@@ -118,7 +118,6 @@ function buildArkFile(arkFile, astRoot) {
|
|
|
118
118
|
logger.warn("This is a MethodDeclaration in ArkFile.");
|
|
119
119
|
let mthd = new ArkMethod_1.ArkMethod();
|
|
120
120
|
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(child, arkFile.getDefaultClass(), mthd, astRoot);
|
|
121
|
-
arkFile.getDefaultClass().addMethod(mthd);
|
|
122
121
|
if (mthd.isExported()) {
|
|
123
122
|
arkFile.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(mthd, arkFile, Position_1.LineColPosition.buildFromNode(child, astRoot)));
|
|
124
123
|
}
|
|
@@ -126,14 +125,13 @@ function buildArkFile(arkFile, astRoot) {
|
|
|
126
125
|
else if (ohos_typescript_1.default.isFunctionDeclaration(child)) {
|
|
127
126
|
let mthd = new ArkMethod_1.ArkMethod();
|
|
128
127
|
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(child, arkFile.getDefaultClass(), mthd, astRoot);
|
|
129
|
-
arkFile.getDefaultClass().addMethod(mthd);
|
|
130
128
|
if (mthd.isExported()) {
|
|
131
129
|
arkFile.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(mthd, arkFile, Position_1.LineColPosition.buildFromNode(child, astRoot)));
|
|
132
130
|
}
|
|
133
131
|
}
|
|
134
132
|
else if (ohos_typescript_1.default.isImportEqualsDeclaration(child) ||
|
|
135
133
|
ohos_typescript_1.default.isImportDeclaration(child)) {
|
|
136
|
-
let importInfos = (0, ArkImportBuilder_1.buildImportInfo)(child, astRoot);
|
|
134
|
+
let importInfos = (0, ArkImportBuilder_1.buildImportInfo)(child, astRoot, arkFile);
|
|
137
135
|
importInfos === null || importInfos === void 0 ? void 0 : importInfos.forEach((element) => {
|
|
138
136
|
element.setDeclaringArkFile(arkFile);
|
|
139
137
|
arkFile.addImportInfo(element);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ts from 'ohos-typescript';
|
|
2
2
|
import { ImportInfo } from '../ArkImport';
|
|
3
|
-
|
|
3
|
+
import { ArkFile } from '../ArkFile';
|
|
4
|
+
export declare function buildImportInfo(node: ts.ImportEqualsDeclaration | ts.ImportDeclaration, sourceFile: ts.SourceFile, arkFile: ArkFile): ImportInfo[];
|
|
4
5
|
//# sourceMappingURL=ArkImportBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkImportBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkImportBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"ArkImportBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkImportBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,wBAAgB,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,uBAAuB,GAAG,EAAE,CAAC,iBAAiB,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,UAAU,EAAE,CAOlJ"}
|
|
@@ -22,17 +22,18 @@ const ohos_typescript_1 = __importDefault(require("ohos-typescript"));
|
|
|
22
22
|
const Position_1 = require("../../base/Position");
|
|
23
23
|
const ArkImport_1 = require("../ArkImport");
|
|
24
24
|
const builderUtils_1 = require("./builderUtils");
|
|
25
|
-
|
|
25
|
+
const IRUtils_1 = require("../../common/IRUtils");
|
|
26
|
+
function buildImportInfo(node, sourceFile, arkFile) {
|
|
26
27
|
if (ohos_typescript_1.default.isImportDeclaration(node)) {
|
|
27
|
-
return buildImportDeclarationNode(node, sourceFile);
|
|
28
|
+
return buildImportDeclarationNode(node, sourceFile, arkFile);
|
|
28
29
|
}
|
|
29
30
|
else if (ohos_typescript_1.default.isImportEqualsDeclaration(node)) {
|
|
30
|
-
return buildImportEqualsDeclarationNode(node, sourceFile);
|
|
31
|
+
return buildImportEqualsDeclarationNode(node, sourceFile, arkFile);
|
|
31
32
|
}
|
|
32
33
|
return [];
|
|
33
34
|
}
|
|
34
35
|
exports.buildImportInfo = buildImportInfo;
|
|
35
|
-
function buildImportDeclarationNode(node, sourceFile) {
|
|
36
|
+
function buildImportDeclarationNode(node, sourceFile, arkFile) {
|
|
36
37
|
const originTsPosition = Position_1.LineColPosition.buildFromNode(node, sourceFile);
|
|
37
38
|
const tsSourceCode = node.getText(sourceFile);
|
|
38
39
|
let importInfos = [];
|
|
@@ -40,11 +41,9 @@ function buildImportDeclarationNode(node, sourceFile) {
|
|
|
40
41
|
if (ohos_typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
|
|
41
42
|
importFrom = node.moduleSpecifier.text;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
let modifiers = 0;
|
|
44
45
|
if (node.modifiers) {
|
|
45
|
-
(0, builderUtils_1.buildModifiers)(node
|
|
46
|
-
modifiers.add(modifier);
|
|
47
|
-
});
|
|
46
|
+
modifiers = (0, builderUtils_1.buildModifiers)(node);
|
|
48
47
|
}
|
|
49
48
|
// just like: import '../xxx'
|
|
50
49
|
if (!node.importClause) {
|
|
@@ -53,6 +52,7 @@ function buildImportDeclarationNode(node, sourceFile) {
|
|
|
53
52
|
let importInfo = new ArkImport_1.ImportInfo();
|
|
54
53
|
importInfo.build(importClauseName, importType, importFrom, originTsPosition, modifiers);
|
|
55
54
|
importInfo.setTsSourceCode(tsSourceCode);
|
|
55
|
+
IRUtils_1.IRUtils.setLeadingComments(importInfo, node, sourceFile, arkFile.getScene().getOptions());
|
|
56
56
|
importInfos.push(importInfo);
|
|
57
57
|
}
|
|
58
58
|
//just like: import fs from 'fs'
|
|
@@ -62,6 +62,7 @@ function buildImportDeclarationNode(node, sourceFile) {
|
|
|
62
62
|
let importInfo = new ArkImport_1.ImportInfo();
|
|
63
63
|
importInfo.build(importClauseName, importType, importFrom, originTsPosition, modifiers);
|
|
64
64
|
importInfo.setTsSourceCode(tsSourceCode);
|
|
65
|
+
IRUtils_1.IRUtils.setLeadingComments(importInfo, node, sourceFile, arkFile.getScene().getOptions());
|
|
65
66
|
importInfos.push(importInfo);
|
|
66
67
|
}
|
|
67
68
|
// just like: import {xxx} from './yyy'
|
|
@@ -75,12 +76,14 @@ function buildImportDeclarationNode(node, sourceFile) {
|
|
|
75
76
|
let importInfo = new ArkImport_1.ImportInfo();
|
|
76
77
|
importInfo.build(importClauseName, importType, importFrom, originTsPosition, modifiers, element.propertyName.text);
|
|
77
78
|
importInfo.setTsSourceCode(tsSourceCode);
|
|
79
|
+
IRUtils_1.IRUtils.setLeadingComments(importInfo, node, sourceFile, arkFile.getScene().getOptions());
|
|
78
80
|
importInfos.push(importInfo);
|
|
79
81
|
}
|
|
80
82
|
else {
|
|
81
83
|
let importInfo = new ArkImport_1.ImportInfo();
|
|
82
84
|
importInfo.build(importClauseName, importType, importFrom, originTsPosition, modifiers);
|
|
83
85
|
importInfo.setTsSourceCode(tsSourceCode);
|
|
86
|
+
IRUtils_1.IRUtils.setLeadingComments(importInfo, node, sourceFile, arkFile.getScene().getOptions());
|
|
84
87
|
importInfos.push(importInfo);
|
|
85
88
|
}
|
|
86
89
|
}
|
|
@@ -96,21 +99,20 @@ function buildImportDeclarationNode(node, sourceFile) {
|
|
|
96
99
|
let nameBeforeAs = '*';
|
|
97
100
|
importInfo.build(importClauseName, importType, importFrom, originTsPosition, modifiers, nameBeforeAs);
|
|
98
101
|
importInfo.setTsSourceCode(tsSourceCode);
|
|
102
|
+
IRUtils_1.IRUtils.setLeadingComments(importInfo, node, sourceFile, arkFile.getScene().getOptions());
|
|
99
103
|
importInfos.push(importInfo);
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
return importInfos;
|
|
103
107
|
}
|
|
104
|
-
function buildImportEqualsDeclarationNode(node, sourceFile) {
|
|
108
|
+
function buildImportEqualsDeclarationNode(node, sourceFile, arkFile) {
|
|
105
109
|
const originTsPosition = Position_1.LineColPosition.buildFromNode(node, sourceFile);
|
|
106
110
|
const tsSourceCode = node.getText(sourceFile);
|
|
107
111
|
let importInfos = [];
|
|
108
112
|
let importType = 'EqualsImport';
|
|
109
|
-
|
|
113
|
+
let modifiers = 0;
|
|
110
114
|
if (node.modifiers) {
|
|
111
|
-
(0, builderUtils_1.buildModifiers)(node
|
|
112
|
-
modifiers.add(modifier);
|
|
113
|
-
});
|
|
115
|
+
modifiers = (0, builderUtils_1.buildModifiers)(node);
|
|
114
116
|
}
|
|
115
117
|
if (node.moduleReference && ohos_typescript_1.default.isExternalModuleReference(node.moduleReference) &&
|
|
116
118
|
node.moduleReference.expression && ohos_typescript_1.default.isStringLiteral(node.moduleReference.expression)) {
|
|
@@ -119,6 +121,7 @@ function buildImportEqualsDeclarationNode(node, sourceFile) {
|
|
|
119
121
|
let importInfo = new ArkImport_1.ImportInfo();
|
|
120
122
|
importInfo.build(importClauseName, importType, importFrom, originTsPosition, modifiers);
|
|
121
123
|
importInfo.setTsSourceCode(tsSourceCode);
|
|
124
|
+
IRUtils_1.IRUtils.setLeadingComments(importInfo, node, sourceFile, arkFile.getScene().getOptions());
|
|
122
125
|
importInfos.push(importInfo);
|
|
123
126
|
}
|
|
124
127
|
return importInfos;
|
|
@@ -55,6 +55,8 @@ export declare class MethodParameter {
|
|
|
55
55
|
setArrayElements(arrayElements: ArrayBindingPatternParameter[]): void;
|
|
56
56
|
}
|
|
57
57
|
export declare function buildDefaultConstructor(arkClass: ArkClass): boolean;
|
|
58
|
-
export declare function buildInitMethod(initMethod: ArkMethod,
|
|
58
|
+
export declare function buildInitMethod(initMethod: ArkMethod, fieldInitializerStmts: Stmt[], thisLocal: Local): void;
|
|
59
59
|
export declare function addInitInConstructor(arkClass: ArkClass): void;
|
|
60
|
+
export declare function isMethodImplementation(node: MethodLikeNode): boolean;
|
|
61
|
+
export declare function checkAndUpdateMethod(method: ArkMethod, cls: ArkClass): void;
|
|
60
62
|
//# sourceMappingURL=ArkMethodBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkMethodBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkMethodBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAa,IAAI,EAAe,MAAM,iBAAiB,CAAC;AAG/D,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"ArkMethodBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkMethodBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAa,IAAI,EAAe,MAAM,iBAAiB,CAAC;AAG/D,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAgBjC,OAAO,EAAmD,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAExF,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAiBzC,MAAM,MAAM,cAAc,GACtB,EAAE,CAAC,mBAAmB,GACtB,EAAE,CAAC,iBAAiB,GACpB,EAAE,CAAC,sBAAsB,GACzB,EAAE,CAAC,aAAa,GAChB,EAAE,CAAC,mBAAmB,GACtB,EAAE,CAAC,kBAAkB,GACrB,EAAE,CAAC,eAAe,GAClB,EAAE,CAAC,6BAA6B,GAChC,EAAE,CAAC,wBAAwB,GAC3B,EAAE,CAAC,gBAAgB,CAAC;AAExB,wBAAgB,iCAAiC,CAAC,cAAc,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EACxC,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,QAYvG;AAED,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC,EAAE,SAAS,QAwDtK;AAwDD,qBAAa,6BAA6B;IACtC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,IAAI,CAAc;IAC1B,OAAO,CAAC,QAAQ,CAAkB;;IAK3B,OAAO;IAIP,OAAO,CAAC,IAAI,EAAE,MAAM;IAIpB,eAAe;IAIf,eAAe,CAAC,YAAY,EAAE,MAAM;IAIpC,UAAU;IAIV,WAAW,CAAC,QAAQ,EAAE,OAAO;CAGvC;AAED,qBAAa,4BAA4B;IACrC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,IAAI,CAAc;IAC1B,OAAO,CAAC,QAAQ,CAAkB;;IAK3B,OAAO;IAIP,OAAO,CAAC,IAAI,EAAE,MAAM;IAIpB,eAAe;IAIf,eAAe,CAAC,YAAY,EAAE,MAAM;IAIpC,UAAU;IAIV,WAAW,CAAC,QAAQ,EAAE,OAAO;CAGvC;AAED,qBAAa,eAAe;IACxB,OAAO,CAAC,IAAI,CAAc;IAC1B,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,aAAa,CAAsC;;IAKpD,OAAO;IAIP,OAAO,CAAC,IAAI,EAAE,MAAM;IAIpB,OAAO;IAIP,OAAO,CAAC,IAAI,EAAE,IAAI;IAIlB,UAAU;IAIV,WAAW,CAAC,QAAQ,EAAE,OAAO;IAI7B,iBAAiB;IAIjB,iBAAiB,CAAC,cAAc,EAAE,OAAO;IAIzC,aAAa,CAAC,OAAO,EAAE,6BAA6B;IAIpD,cAAc;IAId,cAAc,CAAC,WAAW,EAAE,6BAA6B,EAAE;IAI3D,eAAe,CAAC,OAAO,EAAE,4BAA4B;IAIrD,gBAAgB;IAIhB,gBAAgB,CAAC,aAAa,EAAE,4BAA4B,EAAE;CAGxE;AAUD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CA4FnE;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,SAAS,EAAE,qBAAqB,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,GAAG,IAAI,CAsB5G;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,QAoBtD;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAYpE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI,CAsC3E"}
|
|
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
41
|
};
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.addInitInConstructor = exports.buildInitMethod = exports.buildDefaultConstructor = exports.MethodParameter = exports.ArrayBindingPatternParameter = exports.ObjectBindingPatternParameter = exports.buildArkMethodFromArkClass = exports.buildDefaultArkMethodFromArkClass = void 0;
|
|
43
|
+
exports.checkAndUpdateMethod = exports.isMethodImplementation = exports.addInitInConstructor = exports.buildInitMethod = exports.buildDefaultConstructor = exports.MethodParameter = exports.ArrayBindingPatternParameter = exports.ObjectBindingPatternParameter = exports.buildArkMethodFromArkClass = exports.buildDefaultArkMethodFromArkClass = void 0;
|
|
44
44
|
const Type_1 = require("../../base/Type");
|
|
45
45
|
const BodyBuilder_1 = require("../../common/BodyBuilder");
|
|
46
46
|
const ViewTreeBuilder_1 = require("../../graph/builder/ViewTreeBuilder");
|
|
@@ -60,12 +60,15 @@ const Local_1 = require("../../base/Local");
|
|
|
60
60
|
const TSConst_1 = require("../../common/TSConst");
|
|
61
61
|
const Const_1 = require("../../common/Const");
|
|
62
62
|
const ArkSignatureBuilder_1 = require("./ArkSignatureBuilder");
|
|
63
|
+
const IRUtils_1 = require("../../common/IRUtils");
|
|
64
|
+
const ArkError_1 = require("../../common/ArkError");
|
|
63
65
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ArkMethodBuilder');
|
|
64
66
|
function buildDefaultArkMethodFromArkClass(declaringClass, mtd, sourceFile, node) {
|
|
65
67
|
mtd.setDeclaringArkClass(declaringClass);
|
|
66
68
|
const methodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(Const_1.DEFAULT_ARK_METHOD_NAME, true);
|
|
67
69
|
const methodSignature = new ArkSignature_1.MethodSignature(mtd.getDeclaringArkClass().getSignature(), methodSubSignature);
|
|
68
|
-
mtd.
|
|
70
|
+
mtd.setImplementationSignature(methodSignature);
|
|
71
|
+
mtd.setLineCol(0);
|
|
69
72
|
const defaultMethodNode = node ? node : sourceFile;
|
|
70
73
|
let bodyBuilder = new BodyBuilder_1.BodyBuilder(mtd.getSignature(), defaultMethodNode, mtd, sourceFile);
|
|
71
74
|
mtd.setBodyBuilder(bodyBuilder);
|
|
@@ -74,19 +77,15 @@ exports.buildDefaultArkMethodFromArkClass = buildDefaultArkMethodFromArkClass;
|
|
|
74
77
|
function buildArkMethodFromArkClass(methodNode, declaringClass, mtd, sourceFile, declaringMethod) {
|
|
75
78
|
mtd.setDeclaringArkClass(declaringClass);
|
|
76
79
|
if (ohos_typescript_1.default.isFunctionDeclaration(methodNode)) {
|
|
77
|
-
mtd.setAsteriskToken(methodNode.asteriskToken
|
|
80
|
+
mtd.setAsteriskToken(methodNode.asteriskToken !== undefined);
|
|
78
81
|
}
|
|
79
82
|
mtd.setCode(methodNode.getText(sourceFile));
|
|
80
|
-
|
|
81
|
-
mtd.
|
|
82
|
-
mtd.setColumn(character + 1);
|
|
83
|
-
(0, builderUtils_1.buildModifiers)(methodNode, sourceFile).forEach((value) => {
|
|
84
|
-
mtd.addModifier(value);
|
|
85
|
-
});
|
|
83
|
+
mtd.setModifiers((0, builderUtils_1.buildModifiers)(methodNode));
|
|
84
|
+
mtd.setDecorators((0, builderUtils_1.buildDecorators)(methodNode, sourceFile));
|
|
86
85
|
if (methodNode.typeParameters) {
|
|
87
86
|
mtd.setGenericTypes((0, builderUtils_1.buildTypeParameters)(methodNode.typeParameters, sourceFile, mtd));
|
|
88
87
|
}
|
|
89
|
-
// build
|
|
88
|
+
// build methodDeclareSignatures and methodSignature as well as corresponding positions
|
|
90
89
|
const methodName = buildMethodName(methodNode, declaringClass, sourceFile, declaringMethod);
|
|
91
90
|
const methodParameters = [];
|
|
92
91
|
(0, builderUtils_1.buildParameters)(methodNode.parameters, mtd, sourceFile).forEach((parameter) => {
|
|
@@ -98,38 +97,39 @@ function buildArkMethodFromArkClass(methodNode, declaringClass, mtd, sourceFile,
|
|
|
98
97
|
}
|
|
99
98
|
const methodSubSignature = new ArkSignature_1.MethodSubSignature(methodName, methodParameters, returnType, mtd.isStatic());
|
|
100
99
|
const methodSignature = new ArkSignature_1.MethodSignature(mtd.getDeclaringArkClass().getSignature(), methodSubSignature);
|
|
101
|
-
|
|
100
|
+
const { line, character } = ohos_typescript_1.default.getLineAndCharacterOfPosition(sourceFile, methodNode.getStart(sourceFile));
|
|
101
|
+
if (isMethodImplementation(methodNode)) {
|
|
102
|
+
mtd.setImplementationSignature(methodSignature);
|
|
103
|
+
mtd.setLine(line + 1);
|
|
104
|
+
mtd.setColumn(character + 1);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
mtd.setDeclareSignatures(methodSignature);
|
|
108
|
+
mtd.setDeclareLinesAndCols([line + 1], [character + 1]);
|
|
109
|
+
}
|
|
102
110
|
let bodyBuilder = new BodyBuilder_1.BodyBuilder(mtd.getSignature(), methodNode, mtd, sourceFile);
|
|
103
111
|
mtd.setBodyBuilder(bodyBuilder);
|
|
104
112
|
if (mtd.hasBuilderDecorator()) {
|
|
105
113
|
mtd.setViewTree((0, ViewTreeBuilder_1.buildViewTree)(mtd));
|
|
106
114
|
}
|
|
107
115
|
else if (declaringClass.hasComponentDecorator() &&
|
|
108
|
-
mtd.getSubSignature().toString()
|
|
109
|
-
!mtd.
|
|
116
|
+
mtd.getSubSignature().toString() === 'build()' &&
|
|
117
|
+
!mtd.isStatic()) {
|
|
110
118
|
declaringClass.setViewTree((0, ViewTreeBuilder_1.buildViewTree)(mtd));
|
|
111
119
|
}
|
|
120
|
+
checkAndUpdateMethod(mtd, declaringClass);
|
|
112
121
|
declaringClass.addMethod(mtd);
|
|
122
|
+
IRUtils_1.IRUtils.setLeadingComments(mtd, methodNode, sourceFile, mtd.getDeclaringArkFile().getScene().getOptions());
|
|
113
123
|
}
|
|
114
124
|
exports.buildArkMethodFromArkClass = buildArkMethodFromArkClass;
|
|
115
125
|
function buildMethodName(node, declaringClass, sourceFile, declaringMethod) {
|
|
116
126
|
let name = '';
|
|
117
127
|
if (ohos_typescript_1.default.isFunctionDeclaration(node) || ohos_typescript_1.default.isFunctionExpression(node)) {
|
|
118
|
-
|
|
119
|
-
name = node.name.text;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
name = buildAnonymousMethodName(node, declaringClass, declaringMethod);
|
|
123
|
-
}
|
|
128
|
+
name = node.name ? node.name.text : buildAnonymousMethodName(node, declaringClass);
|
|
124
129
|
}
|
|
125
130
|
else if (ohos_typescript_1.default.isFunctionTypeNode(node)) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
name = node.name.getText(sourceFile);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
name = buildAnonymousMethodName(node, declaringClass, declaringMethod);
|
|
132
|
-
}
|
|
131
|
+
//TODO: check name type
|
|
132
|
+
name = node.name ? node.name.getText(sourceFile) : buildAnonymousMethodName(node, declaringClass);
|
|
133
133
|
}
|
|
134
134
|
else if (ohos_typescript_1.default.isMethodDeclaration(node) || ohos_typescript_1.default.isMethodSignature(node)) {
|
|
135
135
|
if (ohos_typescript_1.default.isIdentifier(node.name)) {
|
|
@@ -167,17 +167,21 @@ function buildMethodName(node, declaringClass, sourceFile, declaringMethod) {
|
|
|
167
167
|
name = 'Set-' + node.name.text;
|
|
168
168
|
}
|
|
169
169
|
else if (ohos_typescript_1.default.isArrowFunction(node)) {
|
|
170
|
-
name = buildAnonymousMethodName(node, declaringClass
|
|
170
|
+
name = buildAnonymousMethodName(node, declaringClass);
|
|
171
|
+
}
|
|
172
|
+
if (declaringMethod !== undefined && !declaringMethod.isDefaultArkMethod()) {
|
|
173
|
+
name = buildNestedMethodName(name, declaringMethod.getName());
|
|
171
174
|
}
|
|
172
175
|
return name;
|
|
173
176
|
}
|
|
174
|
-
function buildAnonymousMethodName(node, declaringClass
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
function buildAnonymousMethodName(node, declaringClass) {
|
|
178
|
+
return `${Const_1.ANONYMOUS_METHOD_PREFIX}${declaringClass.getAnonymousMethodNumber()}`;
|
|
179
|
+
}
|
|
180
|
+
function buildNestedMethodName(originName, declaringMethodName) {
|
|
181
|
+
if (originName.startsWith(Const_1.NAME_PREFIX)) {
|
|
182
|
+
return `${originName}${Const_1.NAME_DELIMITER}${declaringMethodName}`;
|
|
178
183
|
}
|
|
179
|
-
|
|
180
|
-
return mtdName;
|
|
184
|
+
return `${Const_1.NAME_PREFIX}${originName}${Const_1.NAME_DELIMITER}${declaringMethodName}`;
|
|
181
185
|
}
|
|
182
186
|
class ObjectBindingPatternParameter {
|
|
183
187
|
constructor() {
|
|
@@ -286,9 +290,9 @@ exports.MethodParameter = MethodParameter;
|
|
|
286
290
|
function needDefaultConstructorInClass(arkClass) {
|
|
287
291
|
const originClassType = arkClass.getCategory();
|
|
288
292
|
return arkClass.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME) == null &&
|
|
289
|
-
(originClassType
|
|
290
|
-
arkClass.getName()
|
|
291
|
-
!arkClass.
|
|
293
|
+
(originClassType === ArkClass_1.ClassCategory.CLASS || originClassType === ArkClass_1.ClassCategory.OBJECT) &&
|
|
294
|
+
arkClass.getName() !== Const_1.DEFAULT_ARK_CLASS_NAME &&
|
|
295
|
+
!arkClass.isDeclare();
|
|
292
296
|
}
|
|
293
297
|
function buildDefaultConstructor(arkClass) {
|
|
294
298
|
if (!needDefaultConstructorInClass(arkClass)) {
|
|
@@ -320,7 +324,8 @@ function buildDefaultConstructor(arkClass) {
|
|
|
320
324
|
let returnType = parentConstructor.getReturnType();
|
|
321
325
|
const methodSubSignature = new ArkSignature_1.MethodSubSignature(TSConst_1.CONSTRUCTOR_NAME, methodParameters, returnType, defaultConstructor.isStatic());
|
|
322
326
|
const methodSignature = new ArkSignature_1.MethodSignature(defaultConstructor.getDeclaringArkClass().getSignature(), methodSubSignature);
|
|
323
|
-
defaultConstructor.
|
|
327
|
+
defaultConstructor.setImplementationSignature(methodSignature);
|
|
328
|
+
defaultConstructor.setLineCol(0);
|
|
324
329
|
const stmts = [];
|
|
325
330
|
let index = 0;
|
|
326
331
|
const parameterLocals = [];
|
|
@@ -343,7 +348,8 @@ function buildDefaultConstructor(arkClass) {
|
|
|
343
348
|
else {
|
|
344
349
|
const methodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
345
350
|
const methodSignature = new ArkSignature_1.MethodSignature(defaultConstructor.getDeclaringArkClass().getSignature(), methodSubSignature);
|
|
346
|
-
defaultConstructor.
|
|
351
|
+
defaultConstructor.setImplementationSignature(methodSignature);
|
|
352
|
+
defaultConstructor.setLineCol(0);
|
|
347
353
|
if (arkClass.getSuperClass()) {
|
|
348
354
|
const superClass = arkClass.getSuperClass();
|
|
349
355
|
const superMethodSubSignature = new ArkSignature_1.MethodSubSignature(TSConst_1.SUPER_NAME, [], Type_1.UnknownType.getInstance());
|
|
@@ -364,19 +370,19 @@ function buildDefaultConstructor(arkClass) {
|
|
|
364
370
|
cfg.setStartingStmt(startingStmt);
|
|
365
371
|
cfg.setDeclaringMethod(defaultConstructor);
|
|
366
372
|
cfg.getStmts().forEach(s => s.setCfg(cfg));
|
|
367
|
-
|
|
368
|
-
defaultConstructor
|
|
373
|
+
defaultConstructor.setBody(new ArkBody_1.ArkBody(locals, cfg));
|
|
374
|
+
checkAndUpdateMethod(defaultConstructor, arkClass);
|
|
369
375
|
arkClass.addMethod(defaultConstructor);
|
|
370
376
|
return true;
|
|
371
377
|
}
|
|
372
378
|
exports.buildDefaultConstructor = buildDefaultConstructor;
|
|
373
|
-
function buildInitMethod(initMethod,
|
|
379
|
+
function buildInitMethod(initMethod, fieldInitializerStmts, thisLocal) {
|
|
374
380
|
const classType = new Type_1.ClassType(initMethod.getDeclaringArkClass().getSignature());
|
|
375
381
|
const assignStmt = new Stmt_1.ArkAssignStmt(thisLocal, new Ref_1.ArkThisRef(classType));
|
|
376
382
|
const block = new BasicBlock_1.BasicBlock();
|
|
377
383
|
block.addStmt(assignStmt);
|
|
378
384
|
const locals = new Set();
|
|
379
|
-
for (const stmt of
|
|
385
|
+
for (const stmt of fieldInitializerStmts) {
|
|
380
386
|
block.addStmt(stmt);
|
|
381
387
|
if (stmt.getDef() && stmt.getDef() instanceof Local_1.Local) {
|
|
382
388
|
locals.add(stmt.getDef());
|
|
@@ -391,13 +397,13 @@ function buildInitMethod(initMethod, stmtMap, thisLocal) {
|
|
|
391
397
|
cfg.setStartingStmt(assignStmt);
|
|
392
398
|
cfg.buildDefUseStmt();
|
|
393
399
|
cfg.setDeclaringMethod(initMethod);
|
|
394
|
-
initMethod.setBody(new ArkBody_1.ArkBody(locals,
|
|
400
|
+
initMethod.setBody(new ArkBody_1.ArkBody(locals, cfg));
|
|
395
401
|
}
|
|
396
402
|
exports.buildInitMethod = buildInitMethod;
|
|
397
403
|
function addInitInConstructor(arkClass) {
|
|
398
404
|
var _a, _b;
|
|
399
405
|
for (const method of arkClass.getMethods(true)) {
|
|
400
|
-
if (method.getName()
|
|
406
|
+
if (method.getName() === TSConst_1.CONSTRUCTOR_NAME) {
|
|
401
407
|
const thisLocal = (_a = method.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(TSConst_1.THIS_NAME);
|
|
402
408
|
if (!thisLocal) {
|
|
403
409
|
continue;
|
|
@@ -409,7 +415,7 @@ function addInitInConstructor(arkClass) {
|
|
|
409
415
|
}
|
|
410
416
|
const firstBlockStmts = [...blocks][0].getStmts();
|
|
411
417
|
let index = 0;
|
|
412
|
-
if (firstBlockStmts[0].getDef() instanceof Local_1.Local && firstBlockStmts[0].getDef().getName()
|
|
418
|
+
if (firstBlockStmts[0].getDef() instanceof Local_1.Local && firstBlockStmts[0].getDef().getName() === TSConst_1.THIS_NAME) {
|
|
413
419
|
index = 1;
|
|
414
420
|
}
|
|
415
421
|
firstBlockStmts.splice(index, 0, initInvokeStmt);
|
|
@@ -417,3 +423,57 @@ function addInitInConstructor(arkClass) {
|
|
|
417
423
|
}
|
|
418
424
|
}
|
|
419
425
|
exports.addInitInConstructor = addInitInConstructor;
|
|
426
|
+
function isMethodImplementation(node) {
|
|
427
|
+
if (ohos_typescript_1.default.isFunctionDeclaration(node) ||
|
|
428
|
+
ohos_typescript_1.default.isMethodDeclaration(node) ||
|
|
429
|
+
ohos_typescript_1.default.isConstructorDeclaration(node) ||
|
|
430
|
+
ohos_typescript_1.default.isGetAccessorDeclaration(node) ||
|
|
431
|
+
ohos_typescript_1.default.isSetAccessorDeclaration(node) ||
|
|
432
|
+
ohos_typescript_1.default.isFunctionExpression(node)) {
|
|
433
|
+
if (node.body !== undefined) {
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
exports.isMethodImplementation = isMethodImplementation;
|
|
440
|
+
function checkAndUpdateMethod(method, cls) {
|
|
441
|
+
let presentMethod;
|
|
442
|
+
if (method.isStatic()) {
|
|
443
|
+
presentMethod = cls.getStaticMethodWithName(method.getName());
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
presentMethod = cls.getMethodWithName(method.getName());
|
|
447
|
+
}
|
|
448
|
+
if (presentMethod === null) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (method.validate().errCode !== ArkError_1.ArkErrorCode.OK || presentMethod.validate().errCode !== ArkError_1.ArkErrorCode.OK) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
const presentDeclareSignatures = presentMethod.getDeclareSignatures();
|
|
455
|
+
const presentDeclareLineCols = presentMethod.getDeclareLineCols();
|
|
456
|
+
const presentImplSignature = presentMethod.getImplementationSignature();
|
|
457
|
+
const newDeclareSignature = method.getDeclareSignatures();
|
|
458
|
+
const newDeclareLineCols = method.getDeclareLineCols();
|
|
459
|
+
const newImplSignature = method.getImplementationSignature();
|
|
460
|
+
if (presentDeclareSignatures !== null && presentImplSignature === null) {
|
|
461
|
+
if (newDeclareSignature === null || presentMethod.getDeclareSignatureIndex(newDeclareSignature[0]) >= 0) {
|
|
462
|
+
method.setDeclareSignatures(presentDeclareSignatures);
|
|
463
|
+
method.setDeclareLineCols(presentDeclareLineCols);
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
method.setDeclareSignatures(presentDeclareSignatures.concat(newDeclareSignature));
|
|
467
|
+
method.setDeclareLineCols(presentDeclareLineCols.concat(newDeclareLineCols));
|
|
468
|
+
}
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (presentDeclareSignatures === null && presentImplSignature !== null) {
|
|
472
|
+
if (newImplSignature === null) {
|
|
473
|
+
method.setImplementationSignature(presentImplSignature);
|
|
474
|
+
method.setLineCol(presentMethod.getLineCol());
|
|
475
|
+
}
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
exports.checkAndUpdateMethod = checkAndUpdateMethod;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkNamespaceBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkNamespaceBuilder.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"ArkNamespaceBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkNamespaceBuilder.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAW/C,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,OAAO,GAAG,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,QAuDnJ"}
|
|
@@ -53,14 +53,14 @@ const ArkExportBuilder_1 = require("./ArkExportBuilder");
|
|
|
53
53
|
const ArkClass_1 = require("../ArkClass");
|
|
54
54
|
const ArkMethod_1 = require("../ArkMethod");
|
|
55
55
|
const ArkSignature_1 = require("../ArkSignature");
|
|
56
|
+
const IRUtils_1 = require("../../common/IRUtils");
|
|
56
57
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ArkNamespaceBuilder');
|
|
57
58
|
function buildArkNamespace(node, declaringInstance, ns, sourceFile) {
|
|
58
59
|
var _a;
|
|
59
60
|
// modifiers
|
|
60
61
|
if (node.modifiers) {
|
|
61
|
-
(0, builderUtils_1.buildModifiers)(node
|
|
62
|
-
|
|
63
|
-
});
|
|
62
|
+
ns.setModifiers((0, builderUtils_1.buildModifiers)(node));
|
|
63
|
+
ns.setDecorators((0, builderUtils_1.buildDecorators)(node, sourceFile));
|
|
64
64
|
}
|
|
65
65
|
if (declaringInstance instanceof ArkFile_1.ArkFile) {
|
|
66
66
|
ns.setDeclaringArkFile(declaringInstance);
|
|
@@ -102,6 +102,7 @@ function buildArkNamespace(node, declaringInstance, ns, sourceFile) {
|
|
|
102
102
|
else {
|
|
103
103
|
logger.warn("JSDocNamespaceDeclaration found.");
|
|
104
104
|
}
|
|
105
|
+
IRUtils_1.IRUtils.setLeadingComments(ns, node, sourceFile, ns.getDeclaringArkFile().getScene().getOptions());
|
|
105
106
|
}
|
|
106
107
|
exports.buildArkNamespace = buildArkNamespace;
|
|
107
108
|
// TODO: check and update
|
|
@@ -136,7 +137,6 @@ function buildNamespaceMembers(node, namespace, sourceFile) {
|
|
|
136
137
|
logger.warn("This is a MethodDeclaration in ArkNamespace.");
|
|
137
138
|
let mthd = new ArkMethod_1.ArkMethod();
|
|
138
139
|
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(child, namespace.getDefaultClass(), mthd, sourceFile);
|
|
139
|
-
namespace.getDefaultClass().addMethod(mthd);
|
|
140
140
|
if (mthd.isExported()) {
|
|
141
141
|
namespace.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(mthd, namespace.getDeclaringArkFile(), Position_1.LineColPosition.buildFromNode(child, sourceFile)));
|
|
142
142
|
}
|
|
@@ -144,7 +144,6 @@ function buildNamespaceMembers(node, namespace, sourceFile) {
|
|
|
144
144
|
else if (ohos_typescript_1.default.isFunctionDeclaration(child)) {
|
|
145
145
|
let mthd = new ArkMethod_1.ArkMethod();
|
|
146
146
|
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(child, namespace.getDefaultClass(), mthd, sourceFile);
|
|
147
|
-
namespace.getDefaultClass().addMethod(mthd);
|
|
148
147
|
if (mthd.isExported()) {
|
|
149
148
|
namespace.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(mthd, namespace.getDeclaringArkFile(), Position_1.LineColPosition.buildFromNode(child, sourceFile)));
|
|
150
149
|
}
|
|
@@ -7,7 +7,8 @@ import { Decorator } from '../../base/Decorator';
|
|
|
7
7
|
import { MethodParameter } from './ArkMethodBuilder';
|
|
8
8
|
export declare function handleQualifiedName(node: ts.QualifiedName): string;
|
|
9
9
|
export declare function handlePropertyAccessExpression(node: ts.PropertyAccessExpression): string;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function buildDecorators(node: ts.Node, sourceFile: ts.SourceFile): Set<Decorator>;
|
|
11
|
+
export declare function buildModifiers(node: ts.Node): number;
|
|
11
12
|
export declare function buildHeritageClauses(heritageClauses: ts.NodeArray<HeritageClause>): Map<string, string>;
|
|
12
13
|
export declare function buildTypeParameters(typeParameters: ts.NodeArray<TypeParameterDeclaration>, sourceFile: ts.SourceFile, arkInstance: ArkMethod | ArkClass): GenericType[];
|
|
13
14
|
export declare function buildParameters(params: ts.NodeArray<ParameterDeclaration>, arkInstance: ArkMethod | ArkField, sourceFile: ts.SourceFile): MethodParameter[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builderUtils.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/builderUtils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,EAAE,EAAE,cAAc,EAAE,oBAAoB,EAAE,QAAQ,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC/G,OAAO,EAIH,WAAW,EAEX,IAAI,EAIP,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAGH,eAAe,EAElB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"builderUtils.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/builderUtils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,EAAE,EAAE,cAAc,EAAE,oBAAoB,EAAE,QAAQ,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC/G,OAAO,EAIH,WAAW,EAEX,IAAI,EAIP,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAGH,eAAe,EAElB,MAAM,oBAAoB,CAAC;AAO5B,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,GAAG,MAAM,CAUlE;AAED,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,EAAE,CAAC,wBAAwB,GAAG,MAAM,CAYxF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,SAAS,CAAC,CAUxF;AA2BD,wBAAgB,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,CAUpD;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBvG;AAED,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,EAAE,CAAC,SAAS,CAAC,wBAAwB,CAAC,EACtD,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,SAAS,GAAG,QAAQ,GAAG,WAAW,EAAE,CAmB/G;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,oBAAoB,CAAC,EAAE,WAAW,EAAE,SAAS,GAAG,QAAQ,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,qBA4GvI;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,GAAG,QAAQ,GAAG,IAAI,CAmCpF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,QAM3F;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,GAAG,EAAE,CAAC,wBAAwB,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAC9E,WAAW,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAkF9E;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,QA8CjD"}
|