arkanalyzer 1.0.11 → 1.0.13
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/lib/callgraph/algorithm/AbstractAnalysis.js +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +1 -1
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +1 -3
- package/lib/core/base/Ref.js +1 -1
- package/lib/core/common/ArkIRTransformer.d.ts +2 -1
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +82 -58
- package/lib/core/common/ArkValueTransformer.d.ts +6 -1
- package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkValueTransformer.js +228 -152
- package/lib/core/common/Builtin.d.ts +3 -1
- package/lib/core/common/Builtin.d.ts.map +1 -1
- package/lib/core/common/Builtin.js +3 -0
- package/lib/core/common/CfgBuilder.js +8 -8
- package/lib/core/common/IRInference.d.ts +4 -1
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +46 -5
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +3 -2
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +9 -10
- package/lib/core/common/ValueUtil.d.ts +2 -2
- package/lib/core/common/ValueUtil.d.ts.map +1 -1
- package/lib/core/graph/BasicBlock.js +1 -1
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +11 -3
- package/lib/core/model/ArkSignature.d.ts +5 -0
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +11 -1
- package/lib/core/model/builder/ArkClassBuilder.js +6 -6
- package/lib/save/source/SourceMethod.js +1 -1
- package/lib/utils/CfgStructualAnalysis.js +1 -1
- package/lib/utils/SparseBitVector.d.ts +3 -0
- package/lib/utils/SparseBitVector.d.ts.map +1 -1
- package/lib/utils/SparseBitVector.js +3 -1
- package/package.json +1 -1
|
@@ -125,6 +125,9 @@ class ArkValueTransformer {
|
|
|
125
125
|
else if (ts.isTemplateExpression(node)) {
|
|
126
126
|
return this.templateExpressionToValueAndStmts(node);
|
|
127
127
|
}
|
|
128
|
+
else if (ts.isTaggedTemplateExpression(node)) {
|
|
129
|
+
return this.taggedTemplateExpressionToValueAndStmts(node);
|
|
130
|
+
}
|
|
128
131
|
else if (ts.isAwaitExpression(node)) {
|
|
129
132
|
return this.awaitExpressionToValueAndStmts(node);
|
|
130
133
|
}
|
|
@@ -191,11 +194,11 @@ class ArkValueTransformer {
|
|
|
191
194
|
tsNodeToSingleAddressValueAndStmts(node) {
|
|
192
195
|
const allStmts = [];
|
|
193
196
|
let { value, valueOriginalPositions, stmts } = this.tsNodeToValueAndStmts(node);
|
|
194
|
-
allStmts.push(
|
|
197
|
+
stmts.forEach(stmt => allStmts.push(stmt));
|
|
195
198
|
if (IRUtils_1.IRUtils.moreThanOneAddress(value)) {
|
|
196
199
|
({ value, valueOriginalPositions, stmts } =
|
|
197
200
|
this.arkIRTransformer.generateAssignStmtForValue(value, valueOriginalPositions));
|
|
198
|
-
allStmts.push(
|
|
201
|
+
stmts.forEach(stmt => allStmts.push(stmt));
|
|
199
202
|
}
|
|
200
203
|
return { value, valueOriginalPositions, stmts: allStmts };
|
|
201
204
|
}
|
|
@@ -210,13 +213,13 @@ class ArkValueTransformer {
|
|
|
210
213
|
const stmts = [];
|
|
211
214
|
const currConditionalOperatorIndex = this.conditionalOperatorNo++;
|
|
212
215
|
const { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts, } = this.conditionToValueAndStmts(conditionalExpression.condition);
|
|
213
|
-
stmts.push(
|
|
216
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
214
217
|
const ifStmt = new Stmt_1.ArkIfStmt(conditionValue);
|
|
215
218
|
ifStmt.setOperandOriginalPositions(conditionPositions);
|
|
216
219
|
stmts.push(ifStmt);
|
|
217
220
|
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT + currConditionalOperatorIndex));
|
|
218
221
|
const { value: whenTrueValue, valueOriginalPositions: whenTruePositions, stmts: whenTrueStmts, } = this.tsNodeToValueAndStmts(conditionalExpression.whenTrue);
|
|
219
|
-
stmts.push(
|
|
222
|
+
whenTrueStmts.forEach(stmt => stmts.push(stmt));
|
|
220
223
|
const resultLocal = this.generateTempLocal();
|
|
221
224
|
const assignStmtWhenTrue = new Stmt_1.ArkAssignStmt(resultLocal, whenTrueValue);
|
|
222
225
|
const resultLocalPosition = [whenTruePositions[0]];
|
|
@@ -224,7 +227,7 @@ class ArkValueTransformer {
|
|
|
224
227
|
stmts.push(assignStmtWhenTrue);
|
|
225
228
|
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT + currConditionalOperatorIndex));
|
|
226
229
|
const { value: whenFalseValue, valueOriginalPositions: whenFalsePositions, stmts: whenFalseStmts, } = this.tsNodeToValueAndStmts(conditionalExpression.whenFalse);
|
|
227
|
-
stmts.push(
|
|
230
|
+
whenFalseStmts.forEach(stmt => stmts.push(stmt));
|
|
228
231
|
const assignStmt = new Stmt_1.ArkAssignStmt(resultLocal, whenFalseValue);
|
|
229
232
|
assignStmt.setOperandOriginalPositions([...resultLocalPosition, ...whenFalsePositions]);
|
|
230
233
|
stmts.push(assignStmt);
|
|
@@ -250,7 +253,7 @@ class ArkValueTransformer {
|
|
|
250
253
|
const anonymousClassType = new Type_1.ClassType(anonymousClassSignature);
|
|
251
254
|
const newExpr = new Expr_1.ArkNewExpr(anonymousClassType);
|
|
252
255
|
const { value: newExprLocal, valueOriginalPositions: newExprLocalPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [objectLiteralExpressionPosition]);
|
|
253
|
-
stmts.push(
|
|
256
|
+
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
254
257
|
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
255
258
|
const constructorMethodSignature = new ArkSignature_1.MethodSignature(anonymousClassSignature, constructorMethodSubSignature);
|
|
256
259
|
const constructorInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newExprLocal, constructorMethodSignature, []);
|
|
@@ -264,10 +267,10 @@ class ArkValueTransformer {
|
|
|
264
267
|
const stmts = [...currStmts];
|
|
265
268
|
const componentExpressionPosition = Position_1.FullPosition.buildFromNode(componentExpression, this.sourceFile);
|
|
266
269
|
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.generateComponentCreationStmts(componentName, args, componentExpressionPosition, argPositionsAllFlat);
|
|
267
|
-
stmts.push(
|
|
270
|
+
componentStmts.forEach(stmt => stmts.push(stmt));
|
|
268
271
|
if (ts.isEtsComponentExpression(componentExpression) && componentExpression.body) {
|
|
269
272
|
for (const statement of componentExpression.body.statements) {
|
|
270
|
-
|
|
273
|
+
this.arkIRTransformer.tsNodeToStmts(statement).forEach(stmt => stmts.push(stmt));
|
|
271
274
|
}
|
|
272
275
|
}
|
|
273
276
|
stmts.push(this.generateComponentPopStmts(componentName, componentExpressionPosition));
|
|
@@ -280,7 +283,7 @@ class ArkValueTransformer {
|
|
|
280
283
|
const classType = new Type_1.ClassType(classSignature);
|
|
281
284
|
const newExpr = new Expr_1.ArkNewExpr(classType);
|
|
282
285
|
const { value: newExprLocal, valueOriginalPositions: newExprPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [componentExpressionPosition]);
|
|
283
|
-
stmts.push(
|
|
286
|
+
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
284
287
|
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
285
288
|
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
286
289
|
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newExprLocal, constructorMethodSignature, args);
|
|
@@ -301,7 +304,7 @@ class ArkValueTransformer {
|
|
|
301
304
|
createViewArgPositionsAll.push(builderMethodPositions);
|
|
302
305
|
}
|
|
303
306
|
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.generateComponentCreationStmts(EtsConst_1.COMPONENT_CUSTOMVIEW, createViewArgs, componentExpressionPosition, createViewArgPositionsAll.flat());
|
|
304
|
-
stmts.push(
|
|
307
|
+
componentStmts.forEach(stmt => stmts.push(stmt));
|
|
305
308
|
stmts.push(this.generateComponentPopStmts(EtsConst_1.COMPONENT_CUSTOMVIEW, componentExpressionPosition));
|
|
306
309
|
return { value: componentValue, valueOriginalPositions: componentPositions, stmts: stmts };
|
|
307
310
|
}
|
|
@@ -323,12 +326,11 @@ class ArkValueTransformer {
|
|
|
323
326
|
etsComponentExpressionToValueAndStmts(etsComponentExpression) {
|
|
324
327
|
const stmts = [];
|
|
325
328
|
const componentName = etsComponentExpression.expression.text;
|
|
326
|
-
const { args: args,
|
|
327
|
-
const argPositionsAllFlat = argPositionsAll.flat();
|
|
329
|
+
const { args: args, argPositions: argPositions } = this.parseArguments(stmts, etsComponentExpression.arguments);
|
|
328
330
|
if ((0, EtsConst_1.isEtsSystemComponent)(componentName)) {
|
|
329
|
-
return this.generateSystemComponentStmt(componentName, args,
|
|
331
|
+
return this.generateSystemComponentStmt(componentName, args, argPositions, etsComponentExpression, stmts);
|
|
330
332
|
}
|
|
331
|
-
return this.generateCustomViewStmt(componentName, args,
|
|
333
|
+
return this.generateCustomViewStmt(componentName, args, argPositions, etsComponentExpression, stmts);
|
|
332
334
|
}
|
|
333
335
|
classExpressionToValueAndStmts(classExpression) {
|
|
334
336
|
const declaringArkClass = this.declaringMethod.getDeclaringArkClass();
|
|
@@ -351,50 +353,110 @@ class ArkValueTransformer {
|
|
|
351
353
|
};
|
|
352
354
|
}
|
|
353
355
|
templateExpressionToValueAndStmts(templateExpression) {
|
|
354
|
-
const stmts =
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
for (let i = 1; i < templateValueCnt; i++) {
|
|
370
|
-
const nextTemplatePositions = templatePositions[i];
|
|
371
|
-
const normalBinopExpr = new Expr_1.ArkNormalBinopExpr(currTemplateValue, templateValues[i], Expr_1.NormalBinaryOperator.Addition);
|
|
372
|
-
const normalBinopExprPositions = [Position_1.FullPosition.merge(currTemplatePositions[0], nextTemplatePositions[0]), ...currTemplatePositions, ...nextTemplatePositions];
|
|
373
|
-
const { value: combinationValue, valueOriginalPositions: combinationPositions, stmts: combinationStmts, } = this.arkIRTransformer.generateAssignStmtForValue(normalBinopExpr, normalBinopExprPositions);
|
|
374
|
-
stmts.push(...combinationStmts);
|
|
375
|
-
currTemplateValue = combinationValue;
|
|
376
|
-
currTemplatePositions = combinationPositions;
|
|
356
|
+
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions } = this.collectTemplateValues(templateExpression);
|
|
357
|
+
const { placeholderStringLocals, placeholderStringLocalPositions, newStmts } = this.processTemplatePlaceholders(placeholderValues, placeholderPositions, stmts);
|
|
358
|
+
return this.combineTemplateParts(stringTextValues, stringTextPositions, placeholderStringLocals, placeholderStringLocalPositions, newStmts);
|
|
359
|
+
}
|
|
360
|
+
processTemplatePlaceholders(placeholderValues, placeholderPositions, currStmts) {
|
|
361
|
+
const placeholderStringLocals = [];
|
|
362
|
+
const placeholderStringLocalPositions = [];
|
|
363
|
+
const newStmts = [...currStmts];
|
|
364
|
+
for (let i = 0; i < placeholderValues.length; i++) {
|
|
365
|
+
let placeholderValue = placeholderValues[i];
|
|
366
|
+
let placeholderPosition = [placeholderPositions[i]];
|
|
367
|
+
let placeholderStmts = [];
|
|
368
|
+
if (!(placeholderValue instanceof Local_1.Local)) {
|
|
369
|
+
({ value: placeholderValue, valueOriginalPositions: placeholderPosition, stmts: placeholderStmts } =
|
|
370
|
+
this.arkIRTransformer.generateAssignStmtForValue(placeholderValue, placeholderPosition));
|
|
377
371
|
}
|
|
378
|
-
|
|
379
|
-
|
|
372
|
+
placeholderStmts.forEach(stmt => newStmts.push(stmt));
|
|
373
|
+
const toStringExpr = new Expr_1.ArkInstanceInvokeExpr(placeholderValue, Builtin_1.Builtin.TO_STRING_METHOD_SIGNATURE, []);
|
|
374
|
+
const toStringExprPosition = [placeholderPosition[0], placeholderPosition[0]];
|
|
375
|
+
const { value: placeholderStringLocal, valueOriginalPositions: placeholderStringPositions, stmts: toStringStmts, } = this.arkIRTransformer.generateAssignStmtForValue(toStringExpr, toStringExprPosition);
|
|
376
|
+
placeholderStringLocals.push(placeholderStringLocal);
|
|
377
|
+
placeholderStringLocalPositions.push(placeholderStringPositions[0]);
|
|
378
|
+
toStringStmts.forEach(stmt => newStmts.push(stmt));
|
|
379
|
+
}
|
|
380
|
+
return { placeholderStringLocals, placeholderStringLocalPositions, newStmts };
|
|
381
|
+
}
|
|
382
|
+
combineTemplateParts(stringTextValues, stringTextPositions, placeholderStringLocals, placeholderStringLocalPositions, currStmts) {
|
|
383
|
+
const templateParts = [];
|
|
384
|
+
const templatePartPositions = [];
|
|
385
|
+
for (let i = 0; i < placeholderStringLocals.length; i++) {
|
|
386
|
+
if (stringTextValues[i] !== ValueUtil_1.ValueUtil.EMPTY_STRING_CONSTANT) {
|
|
387
|
+
templateParts.push(stringTextValues[i]);
|
|
388
|
+
templatePartPositions.push(stringTextPositions[i]);
|
|
389
|
+
}
|
|
390
|
+
templateParts.push(placeholderStringLocals[i]);
|
|
391
|
+
templatePartPositions.push(placeholderStringLocalPositions[i]);
|
|
392
|
+
}
|
|
393
|
+
if (stringTextValues[stringTextValues.length - 1] !== ValueUtil_1.ValueUtil.EMPTY_STRING_CONSTANT) {
|
|
394
|
+
templateParts.push(stringTextValues[stringTextValues.length - 1]);
|
|
395
|
+
templatePartPositions.push(stringTextPositions[stringTextPositions.length - 1]);
|
|
396
|
+
}
|
|
397
|
+
let currTemplateResult = templateParts[0];
|
|
398
|
+
let currTemplateResultPosition = templatePartPositions[0];
|
|
399
|
+
const finalStmts = [...currStmts];
|
|
400
|
+
for (let i = 1; i < templateParts.length; i++) {
|
|
401
|
+
const nextTemplatePartPosition = templatePartPositions[i];
|
|
402
|
+
const normalBinopExpr = new Expr_1.ArkNormalBinopExpr(currTemplateResult, templateParts[i], Expr_1.NormalBinaryOperator.Addition);
|
|
403
|
+
const normalBinopExprPositions = [Position_1.FullPosition.merge(currTemplateResultPosition, nextTemplatePartPosition),
|
|
404
|
+
currTemplateResultPosition, nextTemplatePartPosition];
|
|
405
|
+
const { value: combinationValue, valueOriginalPositions: combinationValuePositions, stmts: combinationStmts, } = this.arkIRTransformer.generateAssignStmtForValue(normalBinopExpr, normalBinopExprPositions);
|
|
406
|
+
combinationStmts.forEach(stmt => finalStmts.push(stmt));
|
|
407
|
+
currTemplateResult = combinationValue;
|
|
408
|
+
currTemplateResultPosition = combinationValuePositions[0];
|
|
409
|
+
}
|
|
410
|
+
return { value: currTemplateResult, valueOriginalPositions: [currTemplateResultPosition], stmts: finalStmts };
|
|
411
|
+
}
|
|
412
|
+
taggedTemplateExpressionToValueAndStmts(taggedTemplateExpression) {
|
|
413
|
+
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions, } = this.collectTemplateValues(taggedTemplateExpression.template);
|
|
414
|
+
const stringTextBaseType = Type_1.StringType.getInstance();
|
|
415
|
+
const stringTextArrayLen = stringTextValues.length;
|
|
416
|
+
const stringTextArrayLenValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(stringTextArrayLen);
|
|
417
|
+
const stringTextArrayLenPosition = Position_1.FullPosition.DEFAULT;
|
|
418
|
+
const { value: templateObjectLocal, valueOriginalPositions: templateObjectLocalPositions, stmts: templateObjectStmts, } = this.generateArrayExprAndStmts(stringTextBaseType, stringTextArrayLenValue, stringTextArrayLenPosition, stringTextArrayLen, stringTextValues, stringTextPositions, stmts, Position_1.FullPosition.DEFAULT, true);
|
|
419
|
+
const placeholderBaseType = Type_1.AnyType.getInstance();
|
|
420
|
+
const placeholdersArrayLen = placeholderValues.length;
|
|
421
|
+
const placeholdersArrayLenValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(placeholdersArrayLen);
|
|
422
|
+
const placeholdersArrayLenPosition = Position_1.FullPosition.DEFAULT;
|
|
423
|
+
const { value: placeholdersLocal, valueOriginalPositions: placeholdersLocalPositions, stmts: placeholdersStmts, } = this.generateArrayExprAndStmts(placeholderBaseType, placeholdersArrayLenValue, placeholdersArrayLenPosition, placeholdersArrayLen, placeholderValues, placeholderPositions, templateObjectStmts, Position_1.FullPosition.DEFAULT, true);
|
|
424
|
+
const taggedFuncArgus = {
|
|
425
|
+
realGenericTypes: undefined, args: [templateObjectLocal, placeholdersLocal],
|
|
426
|
+
argPositions: [templateObjectLocalPositions[0], placeholdersLocalPositions[0]],
|
|
427
|
+
};
|
|
428
|
+
return this.generateInvokeValueAndStmts(taggedTemplateExpression.tag, taggedFuncArgus, placeholdersStmts, taggedTemplateExpression);
|
|
380
429
|
}
|
|
381
|
-
collectTemplateValues(
|
|
382
|
-
|
|
430
|
+
collectTemplateValues(templateLiteral) {
|
|
431
|
+
const stmts = [];
|
|
432
|
+
if (ts.isNoSubstitutionTemplateLiteral(templateLiteral)) {
|
|
433
|
+
const templateLiteralString = templateLiteral.getText(this.sourceFile);
|
|
434
|
+
return {
|
|
435
|
+
stmts: [], stringTextValues: [ValueUtil_1.ValueUtil.createStringConst(templateLiteralString)],
|
|
436
|
+
placeholderValues: [],
|
|
437
|
+
stringTextPositions: [Position_1.FullPosition.buildFromNode(templateLiteral, this.sourceFile)],
|
|
438
|
+
placeholderPositions: [],
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
const head = templateLiteral.head;
|
|
442
|
+
const stringTextValues = [ValueUtil_1.ValueUtil.createStringConst(head.rawText || '')];
|
|
443
|
+
const placeholderValues = [];
|
|
444
|
+
const stringTextPositions = [Position_1.FullPosition.buildFromNode(head, this.sourceFile)];
|
|
445
|
+
const placeholderPositions = [];
|
|
446
|
+
for (const templateSpan of templateLiteral.templateSpans) {
|
|
383
447
|
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(templateSpan.expression);
|
|
384
|
-
|
|
448
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
385
449
|
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
386
450
|
({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } =
|
|
387
451
|
this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions));
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
currTemplateValues.push(exprValue);
|
|
391
|
-
currTemplatePositions.push(exprPositions);
|
|
392
|
-
const literalRawText = templateSpan.literal.rawText;
|
|
393
|
-
if (literalRawText) {
|
|
394
|
-
currTemplateValues.push(ValueUtil_1.ValueUtil.createStringConst(literalRawText));
|
|
395
|
-
currTemplatePositions.push([Position_1.FullPosition.buildFromNode(templateSpan.literal, this.sourceFile)]);
|
|
452
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
396
453
|
}
|
|
454
|
+
placeholderValues.push(exprValue);
|
|
455
|
+
placeholderPositions.push(exprPositions[0]);
|
|
456
|
+
stringTextPositions.push(Position_1.FullPosition.buildFromNode(templateSpan.literal, this.sourceFile));
|
|
457
|
+
stringTextValues.push(ValueUtil_1.ValueUtil.createStringConst(templateSpan.literal.rawText || ''));
|
|
397
458
|
}
|
|
459
|
+
return { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions };
|
|
398
460
|
}
|
|
399
461
|
identifierToValueAndStmts(identifier, variableDefFlag = false) {
|
|
400
462
|
let identifierValue;
|
|
@@ -415,16 +477,16 @@ class ArkValueTransformer {
|
|
|
415
477
|
propertyAccessExpressionToValue(propertyAccessExpression) {
|
|
416
478
|
const stmts = [];
|
|
417
479
|
let { value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts, } = this.tsNodeToValueAndStmts(propertyAccessExpression.expression);
|
|
418
|
-
stmts.push(
|
|
480
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
419
481
|
if (IRUtils_1.IRUtils.moreThanOneAddress(baseValue)) {
|
|
420
482
|
({ value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } =
|
|
421
483
|
this.arkIRTransformer.generateAssignStmtForValue(baseValue, basePositions));
|
|
422
|
-
stmts.push(
|
|
484
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
423
485
|
}
|
|
424
486
|
if (!(baseValue instanceof Local_1.Local)) {
|
|
425
487
|
({ value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } =
|
|
426
488
|
this.arkIRTransformer.generateAssignStmtForValue(baseValue, basePositions));
|
|
427
|
-
stmts.push(
|
|
489
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
428
490
|
}
|
|
429
491
|
const fieldSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(propertyAccessExpression.name.getText(this.sourceFile));
|
|
430
492
|
const fieldRef = new Ref_1.ArkInstanceFieldRef(baseValue, fieldSignature);
|
|
@@ -434,18 +496,18 @@ class ArkValueTransformer {
|
|
|
434
496
|
elementAccessExpressionToValueAndStmts(elementAccessExpression) {
|
|
435
497
|
const stmts = [];
|
|
436
498
|
let { value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } = this.tsNodeToValueAndStmts(elementAccessExpression.expression);
|
|
437
|
-
stmts.push(
|
|
499
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
438
500
|
if (!(baseValue instanceof Local_1.Local)) {
|
|
439
501
|
({ value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } =
|
|
440
502
|
this.arkIRTransformer.generateAssignStmtForValue(baseValue, basePositions));
|
|
441
|
-
stmts.push(
|
|
503
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
442
504
|
}
|
|
443
505
|
let { value: argumentValue, valueOriginalPositions: arguPositions, stmts: argumentStmts, } = this.tsNodeToValueAndStmts(elementAccessExpression.argumentExpression);
|
|
444
|
-
stmts.push(
|
|
506
|
+
argumentStmts.forEach(stmt => stmts.push(stmt));
|
|
445
507
|
if (IRUtils_1.IRUtils.moreThanOneAddress(argumentValue)) {
|
|
446
508
|
({ value: argumentValue, valueOriginalPositions: arguPositions, stmts: argumentStmts } =
|
|
447
509
|
this.arkIRTransformer.generateAssignStmtForValue(argumentValue, arguPositions));
|
|
448
|
-
stmts.push(
|
|
510
|
+
argumentStmts.forEach(stmt => stmts.push(stmt));
|
|
449
511
|
}
|
|
450
512
|
let elementAccessExpr;
|
|
451
513
|
if (baseValue.getType() instanceof Type_1.ArrayType) {
|
|
@@ -463,30 +525,36 @@ class ArkValueTransformer {
|
|
|
463
525
|
}
|
|
464
526
|
callExpressionToValueAndStmts(callExpression) {
|
|
465
527
|
const stmts = [];
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
528
|
+
const argus = this.parseArgumentsOfCallExpression(stmts, callExpression);
|
|
529
|
+
return this.generateInvokeValueAndStmts(callExpression.expression, argus, stmts, callExpression);
|
|
530
|
+
}
|
|
531
|
+
generateInvokeValueAndStmts(functionNameNode, argus, currStmts, callExpression) {
|
|
532
|
+
const stmts = [...currStmts];
|
|
533
|
+
let { value: callerValue, valueOriginalPositions: callerPositions, stmts: callerStmts, } = this.tsNodeToValueAndStmts(functionNameNode);
|
|
534
|
+
callerStmts.forEach(stmt => stmts.push(stmt));
|
|
469
535
|
let invokeValue;
|
|
470
536
|
let invokeValuePositions = [Position_1.FullPosition.buildFromNode(callExpression, this.sourceFile)];
|
|
537
|
+
const { args, argPositions, realGenericTypes } = argus;
|
|
471
538
|
if (callerValue instanceof Ref_1.ArkInstanceFieldRef) {
|
|
472
539
|
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerValue.getFieldName());
|
|
473
540
|
invokeValue = new Expr_1.ArkInstanceInvokeExpr(callerValue.getBase(), methodSignature, args, realGenericTypes);
|
|
474
|
-
invokeValuePositions.push(...callerPositions.slice(1), ...
|
|
541
|
+
invokeValuePositions.push(...callerPositions.slice(1), ...argPositions);
|
|
475
542
|
}
|
|
476
543
|
else if (callerValue instanceof Ref_1.ArkStaticFieldRef) {
|
|
477
544
|
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerValue.getFieldName());
|
|
478
545
|
invokeValue = new Expr_1.ArkStaticInvokeExpr(methodSignature, args, realGenericTypes);
|
|
479
|
-
invokeValuePositions.push(...
|
|
546
|
+
invokeValuePositions.push(...argPositions);
|
|
480
547
|
}
|
|
481
548
|
else if (callerValue instanceof Local_1.Local) {
|
|
482
549
|
const callerName = callerValue.getName();
|
|
483
550
|
let classSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildClassSignatureFromClassName(callerName);
|
|
484
551
|
let cls = ModelUtils_1.ModelUtils.getClass(this.declaringMethod, classSignature);
|
|
485
|
-
if (cls === null || cls === void 0 ? void 0 : cls.hasComponentDecorator()) {
|
|
486
|
-
return this.generateCustomViewStmt(callerName, args,
|
|
552
|
+
if ((cls === null || cls === void 0 ? void 0 : cls.hasComponentDecorator()) && ts.isCallExpression(callExpression)) {
|
|
553
|
+
return this.generateCustomViewStmt(callerName, args, argPositions, callExpression, stmts);
|
|
487
554
|
}
|
|
488
|
-
else if (callerName === EtsConst_1.COMPONENT_FOR_EACH || callerName === EtsConst_1.COMPONENT_LAZY_FOR_EACH)
|
|
489
|
-
|
|
555
|
+
else if ((callerName === EtsConst_1.COMPONENT_FOR_EACH || callerName === EtsConst_1.COMPONENT_LAZY_FOR_EACH) &&
|
|
556
|
+
ts.isCallExpression(callExpression)) { // foreach/lazyforeach will be parsed as ts.callExpression
|
|
557
|
+
return this.generateSystemComponentStmt(callerName, args, argPositions, callExpression, stmts);
|
|
490
558
|
}
|
|
491
559
|
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerName);
|
|
492
560
|
if (callerValue.getType() instanceof Type_1.FunctionType) {
|
|
@@ -495,15 +563,15 @@ class ArkValueTransformer {
|
|
|
495
563
|
else {
|
|
496
564
|
invokeValue = new Expr_1.ArkStaticInvokeExpr(methodSignature, args, realGenericTypes);
|
|
497
565
|
}
|
|
498
|
-
invokeValuePositions.push(...
|
|
566
|
+
invokeValuePositions.push(...argPositions);
|
|
499
567
|
}
|
|
500
568
|
else {
|
|
501
569
|
({ value: callerValue, valueOriginalPositions: callerPositions, stmts: callerStmts } =
|
|
502
570
|
this.arkIRTransformer.generateAssignStmtForValue(callerValue, callerPositions));
|
|
503
|
-
stmts.push(
|
|
571
|
+
callerStmts.forEach(stmt => stmts.push(stmt));
|
|
504
572
|
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerValue.getName());
|
|
505
573
|
invokeValue = new Expr_1.ArkStaticInvokeExpr(methodSignature, args, realGenericTypes);
|
|
506
|
-
invokeValuePositions.push(...
|
|
574
|
+
invokeValuePositions.push(...argPositions);
|
|
507
575
|
}
|
|
508
576
|
return { value: invokeValue, valueOriginalPositions: invokeValuePositions, stmts: stmts };
|
|
509
577
|
}
|
|
@@ -522,12 +590,12 @@ class ArkValueTransformer {
|
|
|
522
590
|
builderMethodIndexes = new Set([1]);
|
|
523
591
|
}
|
|
524
592
|
}
|
|
525
|
-
const { args: args,
|
|
526
|
-
return { realGenericTypes: realGenericTypes, args: args,
|
|
593
|
+
const { args: args, argPositions: argPositions } = this.parseArguments(currStmts, callExpression.arguments, builderMethodIndexes);
|
|
594
|
+
return { realGenericTypes: realGenericTypes, args: args, argPositions: argPositions };
|
|
527
595
|
}
|
|
528
596
|
parseArguments(currStmts, argumentNodes, builderMethodIndexes) {
|
|
529
597
|
const args = [];
|
|
530
|
-
const
|
|
598
|
+
const argPositions = [];
|
|
531
599
|
if (argumentNodes) {
|
|
532
600
|
for (let i = 0; i < argumentNodes.length; i++) {
|
|
533
601
|
const argument = argumentNodes[i];
|
|
@@ -536,20 +604,20 @@ class ArkValueTransformer {
|
|
|
536
604
|
this.builderMethodContextFlag = true;
|
|
537
605
|
this.arkIRTransformer.setBuilderMethodContextFlag(true);
|
|
538
606
|
}
|
|
539
|
-
let { value: argValue, valueOriginalPositions:
|
|
607
|
+
let { value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts, } = this.tsNodeToValueAndStmts(argument);
|
|
540
608
|
this.builderMethodContextFlag = prevBuilderMethodContextFlag;
|
|
541
609
|
this.arkIRTransformer.setBuilderMethodContextFlag(prevBuilderMethodContextFlag);
|
|
542
610
|
argStmts.forEach(s => currStmts.push(s));
|
|
543
611
|
if (IRUtils_1.IRUtils.moreThanOneAddress(argValue)) {
|
|
544
|
-
({ value: argValue, valueOriginalPositions:
|
|
612
|
+
({ value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts } =
|
|
545
613
|
this.arkIRTransformer.generateAssignStmtForValue(argValue, argPositions));
|
|
546
614
|
argStmts.forEach(s => currStmts.push(s));
|
|
547
615
|
}
|
|
548
616
|
args.push(argValue);
|
|
549
|
-
|
|
617
|
+
argPositions.push(argPositionsSingle[0]);
|
|
550
618
|
}
|
|
551
619
|
}
|
|
552
|
-
return { args: args,
|
|
620
|
+
return { args: args, argPositions: argPositions };
|
|
553
621
|
}
|
|
554
622
|
callableNodeToValueAndStmts(callableNode) {
|
|
555
623
|
const declaringClass = this.declaringMethod.getDeclaringArkClass();
|
|
@@ -589,12 +657,12 @@ class ArkValueTransformer {
|
|
|
589
657
|
const classType = new Type_1.ClassType(classSignature, realGenericTypes);
|
|
590
658
|
const newExpr = new Expr_1.ArkNewExpr(classType);
|
|
591
659
|
const { value: newLocal, valueOriginalPositions: newLocalPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [Position_1.FullPosition.buildFromNode(newExpression, this.sourceFile)]);
|
|
592
|
-
stmts.push(
|
|
660
|
+
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
593
661
|
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
594
662
|
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
595
|
-
const { args: argValues,
|
|
663
|
+
const { args: argValues, argPositions: argPositions } = this.parseArguments(stmts, newExpression.arguments);
|
|
596
664
|
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newLocal, constructorMethodSignature, argValues);
|
|
597
|
-
const instanceInvokeExprPositions = [newLocalPositions[0], ...newLocalPositions, ...
|
|
665
|
+
const instanceInvokeExprPositions = [newLocalPositions[0], ...newLocalPositions, ...argPositions];
|
|
598
666
|
const invokeStmt = new Stmt_1.ArkInvokeStmt(instanceInvokeExpr);
|
|
599
667
|
invokeStmt.setOperandOriginalPositions(instanceInvokeExprPositions);
|
|
600
668
|
stmts.push(invokeStmt);
|
|
@@ -609,57 +677,49 @@ class ArkValueTransformer {
|
|
|
609
677
|
}
|
|
610
678
|
}
|
|
611
679
|
const stmts = [];
|
|
612
|
-
const { args: argumentValues,
|
|
613
|
-
let
|
|
614
|
-
let arrayLengthValue
|
|
680
|
+
const { args: argumentValues, argPositions: argPositions } = this.parseArguments(stmts, newArrayExpression.arguments);
|
|
681
|
+
let argumentsLength = newArrayExpression.arguments ? newArrayExpression.arguments.length : 0;
|
|
682
|
+
let arrayLengthValue;
|
|
683
|
+
let arrayLength = -1;
|
|
615
684
|
let arrayLengthPosition = Position_1.FullPosition.DEFAULT;
|
|
616
|
-
|
|
617
|
-
|
|
685
|
+
if ((argumentsLength === 1) &&
|
|
686
|
+
((argumentValues[0].getType() instanceof Type_1.NumberType) || argumentValues[0].getType() instanceof
|
|
687
|
+
Type_1.UnknownType)) {
|
|
618
688
|
arrayLengthValue = argumentValues[0];
|
|
619
|
-
arrayLengthPosition =
|
|
620
|
-
|
|
689
|
+
arrayLengthPosition = argPositions[0];
|
|
690
|
+
}
|
|
691
|
+
else {
|
|
692
|
+
arrayLengthValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(argumentsLength);
|
|
693
|
+
arrayLength = argumentsLength;
|
|
621
694
|
}
|
|
622
695
|
if (baseType instanceof Type_1.UnknownType) {
|
|
623
|
-
if ((
|
|
696
|
+
if ((argumentsLength > 1) && !(argumentValues[0].getType() instanceof Type_1.UnknownType)) {
|
|
624
697
|
baseType = argumentValues[0].getType();
|
|
625
698
|
}
|
|
626
699
|
else {
|
|
627
700
|
baseType = Type_1.AnyType.getInstance();
|
|
628
701
|
}
|
|
629
702
|
}
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
arrayLengthPosition];
|
|
633
|
-
const { value: arrayLocal, valueOriginalPositions: arrayLocalPositions, stmts: arrayStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newArrayExpr, newArrayExprPositions);
|
|
634
|
-
stmts.push(...arrayStmts);
|
|
635
|
-
if (!arrayLengthFlag) {
|
|
636
|
-
for (let i = 0; i < arrayLength; i++) {
|
|
637
|
-
const arrayRef = new Ref_1.ArkArrayRef(arrayLocal, ValueUtil_1.ValueUtil.getOrCreateNumberConst(i));
|
|
638
|
-
const arrayRefPositions = [arrayLocalPositions[0], ...arrayLocalPositions, Position_1.FullPosition.DEFAULT];
|
|
639
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(arrayRef, argumentValues[i]);
|
|
640
|
-
assignStmt.setOperandOriginalPositions([...arrayRefPositions, ...argPositionsAll[i]]);
|
|
641
|
-
stmts.push(assignStmt);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
return { value: arrayLocal, valueOriginalPositions: arrayLocalPositions, stmts: stmts };
|
|
703
|
+
const newArrayExprPosition = Position_1.FullPosition.buildFromNode(newArrayExpression, this.sourceFile);
|
|
704
|
+
return this.generateArrayExprAndStmts(baseType, arrayLengthValue, arrayLengthPosition, arrayLength, argumentValues, argPositions, stmts, newArrayExprPosition, false);
|
|
645
705
|
}
|
|
646
706
|
arrayLiteralExpressionToValueAndStmts(arrayLiteralExpression) {
|
|
647
707
|
const stmts = [];
|
|
648
708
|
const elementTypes = new Set();
|
|
649
709
|
const elementValues = [];
|
|
650
|
-
const
|
|
710
|
+
const elementPositions = [];
|
|
651
711
|
const arrayLength = arrayLiteralExpression.elements.length;
|
|
652
712
|
for (const element of arrayLiteralExpression.elements) {
|
|
653
713
|
let { value: elementValue, valueOriginalPositions: elementPosition, stmts: elementStmts, } = this.tsNodeToValueAndStmts(element);
|
|
654
|
-
stmts.push(
|
|
714
|
+
elementStmts.forEach(stmt => stmts.push(stmt));
|
|
655
715
|
if (IRUtils_1.IRUtils.moreThanOneAddress(elementValue)) {
|
|
656
716
|
({ value: elementValue, valueOriginalPositions: elementPosition, stmts: elementStmts } =
|
|
657
717
|
this.arkIRTransformer.generateAssignStmtForValue(elementValue, elementPosition));
|
|
658
|
-
stmts.push(
|
|
718
|
+
elementStmts.forEach(stmt => stmts.push(stmt));
|
|
659
719
|
}
|
|
660
720
|
elementValues.push(elementValue);
|
|
661
721
|
elementTypes.add(elementValue.getType());
|
|
662
|
-
|
|
722
|
+
elementPositions.push(elementPosition[0]);
|
|
663
723
|
}
|
|
664
724
|
let baseType = Type_1.AnyType.getInstance();
|
|
665
725
|
if (elementTypes.size === 1) {
|
|
@@ -668,28 +728,33 @@ class ArkValueTransformer {
|
|
|
668
728
|
else if (elementTypes.size > 1) {
|
|
669
729
|
baseType = new Type_1.UnionType(Array.from(elementTypes));
|
|
670
730
|
}
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
stmts
|
|
731
|
+
const newArrayExprPosition = Position_1.FullPosition.buildFromNode(arrayLiteralExpression, this.sourceFile);
|
|
732
|
+
return this.generateArrayExprAndStmts(baseType, ValueUtil_1.ValueUtil.getOrCreateNumberConst(arrayLength), Position_1.FullPosition.DEFAULT, arrayLength, elementValues, elementPositions, stmts, newArrayExprPosition, true);
|
|
733
|
+
}
|
|
734
|
+
generateArrayExprAndStmts(baseType, arrayLengthValue, arrayLengthPosition, arrayLength, initializerValues, initializerPositions, currStmts, newArrayExprPosition, fromLiteral) {
|
|
735
|
+
const stmts = [...currStmts];
|
|
736
|
+
const newArrayExpr = new Expr_1.ArkNewArrayExpr(baseType, arrayLengthValue, fromLiteral);
|
|
737
|
+
const newArrayExprPositions = [newArrayExprPosition, arrayLengthPosition];
|
|
738
|
+
const { value: arrayLocal, valueOriginalPositions: arrayLocalPositions, stmts: arrayStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newArrayExpr, newArrayExprPositions);
|
|
739
|
+
arrayStmts.forEach(stmt => stmts.push(stmt));
|
|
676
740
|
for (let i = 0; i < arrayLength; i++) {
|
|
677
|
-
const
|
|
678
|
-
const
|
|
679
|
-
const
|
|
680
|
-
assignStmt.
|
|
741
|
+
const indexValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(i);
|
|
742
|
+
const arrayRef = new Ref_1.ArkArrayRef(arrayLocal, indexValue);
|
|
743
|
+
const arrayRefPositions = [arrayLocalPositions[0], ...arrayLocalPositions, Position_1.FullPosition.DEFAULT];
|
|
744
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(arrayRef, initializerValues[i]);
|
|
745
|
+
assignStmt.setOperandOriginalPositions([...arrayRefPositions, initializerPositions[i]]);
|
|
681
746
|
stmts.push(assignStmt);
|
|
682
747
|
}
|
|
683
|
-
return { value:
|
|
748
|
+
return { value: arrayLocal, valueOriginalPositions: arrayLocalPositions, stmts: stmts };
|
|
684
749
|
}
|
|
685
750
|
prefixUnaryExpressionToValueAndStmts(prefixUnaryExpression) {
|
|
686
751
|
const stmts = [];
|
|
687
752
|
let { value: operandValue, valueOriginalPositions: operandPositions, stmts: operandStmts, } = this.tsNodeToValueAndStmts(prefixUnaryExpression.operand);
|
|
688
|
-
stmts.push(
|
|
753
|
+
operandStmts.forEach(stmt => stmts.push(stmt));
|
|
689
754
|
if (IRUtils_1.IRUtils.moreThanOneAddress(operandValue)) {
|
|
690
755
|
({ value: operandValue, valueOriginalPositions: operandPositions, stmts: operandStmts } =
|
|
691
756
|
this.arkIRTransformer.generateAssignStmtForValue(operandValue, operandPositions));
|
|
692
|
-
stmts.push(
|
|
757
|
+
operandStmts.forEach(stmt => stmts.push(stmt));
|
|
693
758
|
}
|
|
694
759
|
const operatorToken = prefixUnaryExpression.operator;
|
|
695
760
|
let exprPositions = [Position_1.FullPosition.buildFromNode(prefixUnaryExpression, this.sourceFile)];
|
|
@@ -722,11 +787,11 @@ class ArkValueTransformer {
|
|
|
722
787
|
postfixUnaryExpressionToValueAndStmts(postfixUnaryExpression) {
|
|
723
788
|
const stmts = [];
|
|
724
789
|
let { value: operandValue, valueOriginalPositions: operandPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(postfixUnaryExpression.operand);
|
|
725
|
-
stmts.push(
|
|
790
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
726
791
|
if (IRUtils_1.IRUtils.moreThanOneAddress(operandValue)) {
|
|
727
792
|
({ value: operandValue, valueOriginalPositions: operandPositions, stmts: exprStmts } =
|
|
728
793
|
this.arkIRTransformer.generateAssignStmtForValue(operandValue, operandPositions));
|
|
729
|
-
stmts.push(
|
|
794
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
730
795
|
}
|
|
731
796
|
let value;
|
|
732
797
|
let exprPositions = [Position_1.FullPosition.buildFromNode(postfixUnaryExpression, this.sourceFile)];
|
|
@@ -749,11 +814,11 @@ class ArkValueTransformer {
|
|
|
749
814
|
awaitExpressionToValueAndStmts(awaitExpression) {
|
|
750
815
|
const stmts = [];
|
|
751
816
|
let { value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts, } = this.tsNodeToValueAndStmts(awaitExpression.expression);
|
|
752
|
-
stmts.push(
|
|
817
|
+
promiseStmts.forEach(stmt => stmts.push(stmt));
|
|
753
818
|
if (IRUtils_1.IRUtils.moreThanOneAddress(promiseValue)) {
|
|
754
819
|
({ value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts } =
|
|
755
820
|
this.arkIRTransformer.generateAssignStmtForValue(promiseValue, promisePositions));
|
|
756
|
-
stmts.push(
|
|
821
|
+
promiseStmts.forEach(stmt => stmts.push(stmt));
|
|
757
822
|
}
|
|
758
823
|
const awaitExpr = new Expr_1.ArkAwaitExpr(promiseValue);
|
|
759
824
|
const awaitExprPositions = [Position_1.FullPosition.buildFromNode(awaitExpression, this.sourceFile), ...promisePositions];
|
|
@@ -779,7 +844,9 @@ class ArkValueTransformer {
|
|
|
779
844
|
return { value: deleteExpr, valueOriginalPositions: deleteExprPositions, stmts: stmts };
|
|
780
845
|
}
|
|
781
846
|
voidExpressionToValueAndStmts(voidExpression) {
|
|
782
|
-
const stmts = this.
|
|
847
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts } = this.tsNodeToValueAndStmts(voidExpression.expression);
|
|
848
|
+
const { stmts: exprStmts } = this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions);
|
|
849
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
783
850
|
return { value: ValueUtil_1.ValueUtil.getUndefinedConst(), valueOriginalPositions: [Position_1.FullPosition.DEFAULT], stmts: stmts };
|
|
784
851
|
}
|
|
785
852
|
nonNullExpressionToValueAndStmts(nonNullExpression) {
|
|
@@ -797,11 +864,11 @@ class ArkValueTransformer {
|
|
|
797
864
|
asExpressionToValueAndStmts(asExpression) {
|
|
798
865
|
const stmts = [];
|
|
799
866
|
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(asExpression.expression);
|
|
800
|
-
stmts.push(
|
|
867
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
801
868
|
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
802
869
|
({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } =
|
|
803
870
|
this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions));
|
|
804
|
-
stmts.push(
|
|
871
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
805
872
|
}
|
|
806
873
|
const castExpr = new Expr_1.ArkCastExpr(exprValue, this.resolveTypeNode(asExpression.type));
|
|
807
874
|
const castExprPositions = [Position_1.FullPosition.buildFromNode(asExpression, this.sourceFile), ...exprPositions];
|
|
@@ -860,10 +927,14 @@ class ArkValueTransformer {
|
|
|
860
927
|
assignStmt.setOperandOriginalPositions([...leftPositions, ...rightPositions]);
|
|
861
928
|
if (ts.isArrayBindingPattern(leftOpNode) || ts.isArrayLiteralExpression(leftOpNode) ||
|
|
862
929
|
ts.isObjectBindingPattern(leftOpNode) || ts.isObjectLiteralExpression(leftOpNode)) {
|
|
863
|
-
stmts.push(
|
|
930
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
931
|
+
stmts.push(assignStmt);
|
|
932
|
+
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
864
933
|
}
|
|
865
934
|
else {
|
|
866
|
-
stmts.push(
|
|
935
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
936
|
+
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
937
|
+
stmts.push(assignStmt);
|
|
867
938
|
}
|
|
868
939
|
}
|
|
869
940
|
else {
|
|
@@ -879,7 +950,7 @@ class ArkValueTransformer {
|
|
|
879
950
|
if (rightOpNode) {
|
|
880
951
|
({ value: rightValue, valueOriginalPositions: rightPositions, stmts: tempRightStmts } =
|
|
881
952
|
this.tsNodeToValueAndStmts(rightOpNode));
|
|
882
|
-
rightStmts.push(
|
|
953
|
+
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
883
954
|
}
|
|
884
955
|
else {
|
|
885
956
|
rightValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
@@ -888,7 +959,7 @@ class ArkValueTransformer {
|
|
|
888
959
|
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue) && IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
889
960
|
({ value: rightValue, valueOriginalPositions: rightPositions, stmts: tempRightStmts } =
|
|
890
961
|
this.arkIRTransformer.generateAssignStmtForValue(rightValue, rightPositions));
|
|
891
|
-
rightStmts.push(
|
|
962
|
+
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
892
963
|
}
|
|
893
964
|
return { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts };
|
|
894
965
|
}
|
|
@@ -959,20 +1030,20 @@ class ArkValueTransformer {
|
|
|
959
1030
|
const declarationType = Type_1.UnknownType.getInstance();
|
|
960
1031
|
return this.assignmentToValueAndStmts(leftOpNode, rightOpNode, false, false, declarationType, true);
|
|
961
1032
|
}
|
|
962
|
-
else if (ArkValueTransformer.
|
|
1033
|
+
else if (ArkValueTransformer.isCompoundAssignmentOperator(operatorToken.kind)) {
|
|
963
1034
|
return this.compoundAssignmentToValueAndStmts(binaryExpression);
|
|
964
1035
|
}
|
|
965
1036
|
const stmts = [];
|
|
966
1037
|
const binaryExpressionPosition = Position_1.FullPosition.buildFromNode(binaryExpression, this.sourceFile);
|
|
967
1038
|
const { value: opValue1, valueOriginalPositions: opPositions1, stmts: opStmts1, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.left);
|
|
968
|
-
stmts.push(
|
|
1039
|
+
opStmts1.forEach(stmt => stmts.push(stmt));
|
|
969
1040
|
if (operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword) {
|
|
970
1041
|
const instanceOfExpr = new Expr_1.ArkInstanceOfExpr(opValue1, new Type_1.UnclearReferenceType(binaryExpression.right.getText(this.sourceFile)));
|
|
971
1042
|
const instanceOfExprPositions = [binaryExpressionPosition, ...opPositions1];
|
|
972
1043
|
return { value: instanceOfExpr, valueOriginalPositions: instanceOfExprPositions, stmts: stmts };
|
|
973
1044
|
}
|
|
974
1045
|
const { value: opValue2, valueOriginalPositions: opPositions2, stmts: opStmts2, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
975
|
-
stmts.push(
|
|
1046
|
+
opStmts2.forEach(stmt => stmts.push(stmt));
|
|
976
1047
|
let exprValue;
|
|
977
1048
|
let exprValuePositions = [binaryExpressionPosition];
|
|
978
1049
|
if (operatorToken.kind === ts.SyntaxKind.CommaToken) {
|
|
@@ -999,14 +1070,14 @@ class ArkValueTransformer {
|
|
|
999
1070
|
compoundAssignmentToValueAndStmts(binaryExpression) {
|
|
1000
1071
|
const stmts = [];
|
|
1001
1072
|
let { value: leftValue, valueOriginalPositions: leftPositions, stmts: leftStmts, } = this.tsNodeToValueAndStmts(binaryExpression.left);
|
|
1002
|
-
stmts.push(
|
|
1073
|
+
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
1003
1074
|
let { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.tsNodeToValueAndStmts(binaryExpression.right);
|
|
1004
|
-
stmts.push(
|
|
1075
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1005
1076
|
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue) && IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
1006
1077
|
const { value: newRightValue, valueOriginalPositions: newRightPositions, stmts: rightStmts, } = this.arkIRTransformer.generateAssignStmtForValue(rightValue, rightPositions);
|
|
1007
1078
|
rightValue = newRightValue;
|
|
1008
1079
|
rightPositions = newRightPositions;
|
|
1009
|
-
stmts.push(
|
|
1080
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1010
1081
|
}
|
|
1011
1082
|
let leftOpValue;
|
|
1012
1083
|
let leftOpPositions;
|
|
@@ -1066,7 +1137,7 @@ class ArkValueTransformer {
|
|
|
1066
1137
|
conditionToValueAndStmts(condition) {
|
|
1067
1138
|
const stmts = [];
|
|
1068
1139
|
let { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts, } = this.tsNodeToValueAndStmts(condition);
|
|
1069
|
-
stmts.push(
|
|
1140
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
1070
1141
|
let conditionExpr;
|
|
1071
1142
|
if ((conditionValue instanceof Expr_1.AbstractBinopExpr) && this.isRelationalOperator(conditionValue.getOperator())) {
|
|
1072
1143
|
const operator = conditionValue.getOperator();
|
|
@@ -1079,7 +1150,7 @@ class ArkValueTransformer {
|
|
|
1079
1150
|
valueOriginalPositions: conditionPositions,
|
|
1080
1151
|
stmts: conditionStmts,
|
|
1081
1152
|
} = this.arkIRTransformer.generateAssignStmtForValue(conditionValue, conditionPositions));
|
|
1082
|
-
stmts.push(
|
|
1153
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
1083
1154
|
}
|
|
1084
1155
|
conditionExpr = new Expr_1.ArkConditionExpr(conditionValue, ValueUtil_1.ValueUtil.getOrCreateNumberConst(0), Expr_1.RelationalBinaryOperator.InEquality);
|
|
1085
1156
|
conditionPositions = [conditionPositions[0], ...conditionPositions, Position_1.FullPosition.DEFAULT];
|
|
@@ -1333,20 +1404,25 @@ class ArkValueTransformer {
|
|
|
1333
1404
|
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(functionTypeNode, declaringClass, anonymousMethod, this.sourceFile);
|
|
1334
1405
|
return new Type_1.FunctionType(anonymousMethod.getSignature());
|
|
1335
1406
|
}
|
|
1407
|
+
static isCompoundAssignmentOperator(operator) {
|
|
1408
|
+
const compoundAssignmentOperators = [
|
|
1409
|
+
ts.SyntaxKind.PlusEqualsToken,
|
|
1410
|
+
ts.SyntaxKind.MinusEqualsToken,
|
|
1411
|
+
ts.SyntaxKind.AsteriskAsteriskEqualsToken,
|
|
1412
|
+
ts.SyntaxKind.AsteriskEqualsToken,
|
|
1413
|
+
ts.SyntaxKind.SlashEqualsToken,
|
|
1414
|
+
ts.SyntaxKind.PercentEqualsToken,
|
|
1415
|
+
ts.SyntaxKind.AmpersandEqualsToken,
|
|
1416
|
+
ts.SyntaxKind.BarEqualsToken,
|
|
1417
|
+
ts.SyntaxKind.CaretEqualsToken,
|
|
1418
|
+
ts.SyntaxKind.LessThanLessThanEqualsToken,
|
|
1419
|
+
ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken,
|
|
1420
|
+
ts.SyntaxKind.GreaterThanGreaterThanEqualsToken,
|
|
1421
|
+
ts.SyntaxKind.BarBarEqualsToken,
|
|
1422
|
+
ts.SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
1423
|
+
ts.SyntaxKind.QuestionQuestionEqualsToken,
|
|
1424
|
+
];
|
|
1425
|
+
return compoundAssignmentOperators.includes(operator);
|
|
1426
|
+
}
|
|
1336
1427
|
}
|
|
1337
1428
|
exports.ArkValueTransformer = ArkValueTransformer;
|
|
1338
|
-
ArkValueTransformer.compoundAssignmentOperators = new Set([ts.SyntaxKind.PlusEqualsToken,
|
|
1339
|
-
ts.SyntaxKind.MinusEqualsToken,
|
|
1340
|
-
ts.SyntaxKind.AsteriskAsteriskEqualsToken,
|
|
1341
|
-
ts.SyntaxKind.AsteriskEqualsToken,
|
|
1342
|
-
ts.SyntaxKind.SlashEqualsToken,
|
|
1343
|
-
ts.SyntaxKind.PercentEqualsToken,
|
|
1344
|
-
ts.SyntaxKind.AmpersandEqualsToken,
|
|
1345
|
-
ts.SyntaxKind.BarEqualsToken,
|
|
1346
|
-
ts.SyntaxKind.CaretEqualsToken,
|
|
1347
|
-
ts.SyntaxKind.LessThanLessThanEqualsToken,
|
|
1348
|
-
ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken,
|
|
1349
|
-
ts.SyntaxKind.GreaterThanGreaterThanEqualsToken,
|
|
1350
|
-
ts.SyntaxKind.BarBarEqualsToken,
|
|
1351
|
-
ts.SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
1352
|
-
ts.SyntaxKind.QuestionQuestionEqualsToken]);
|