mirror of
https://github.com/openharmony/ark_ts2abc.git
synced 2026-07-21 08:25:24 -04:00
fix function's name setting
Signed-off-by: hufeng <hufeng20@huawei.com> Change-Id: Ia4e1e219c4f8180ad0363164561ad6a76bb4ae40
This commit is contained in:
@@ -71,6 +71,8 @@ import {
|
||||
EcmaStownbyindex,
|
||||
EcmaStownbyname,
|
||||
EcmaStownbyvalue,
|
||||
EcmaStownbynamewithnameset,
|
||||
EcmaStownbyvaluewithnameset,
|
||||
EcmaStsuperbyname,
|
||||
EcmaStsuperbyvalue,
|
||||
EcmaSupercall,
|
||||
@@ -218,16 +220,16 @@ export function storeObjByValue(obj: VReg, prop: VReg): IRNode {
|
||||
return new EcmaStobjbyvalue(obj, prop);
|
||||
}
|
||||
|
||||
export function storeOwnByName(obj: VReg, key: string): IRNode {
|
||||
return new EcmaStownbyname(key, obj);
|
||||
export function storeOwnByName(obj: VReg, key: string, nameSetting: boolean): IRNode {
|
||||
return nameSetting ? new EcmaStownbynamewithnameset(key, obj) : new EcmaStownbyname(key, obj);
|
||||
}
|
||||
|
||||
export function storeOwnByIndex(obj: VReg, index: number) {
|
||||
return new EcmaStownbyindex(obj, new Imm(ResultType.Int, index));
|
||||
}
|
||||
|
||||
export function storeOwnByValue(obj: VReg, value: VReg) {
|
||||
return new EcmaStownbyvalue(obj, value);
|
||||
export function storeOwnByValue(obj: VReg, value: VReg, nameSetting: boolean) {
|
||||
return nameSetting ? new EcmaStownbyvaluewithnameset(obj, value) : new EcmaStownbyvalue(obj, value);
|
||||
}
|
||||
|
||||
export function throwIfSuperNotCorrectCall(num: number) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import * as jshelpers from "../jshelpers";
|
||||
import { getParamLengthOfFunc } from "../base/util";
|
||||
import { CacheList, getVregisterCache } from "../base/vregisterCache";
|
||||
import { isInteger } from "./numericLiteral";
|
||||
import { findInnerExprOfParenthesis } from "./parenthesizedExpression";
|
||||
import { PandaGen } from "../pandagen";
|
||||
import { VReg } from "../irnodes";
|
||||
import { PropertyKind, Property, generatePropertyFromExpr } from "../base/properties";
|
||||
@@ -205,12 +206,13 @@ function compileComputedProperty(compiler: Compiler, prop: Property, objReg: VRe
|
||||
switch (prop.getValue().kind) {
|
||||
case ts.SyntaxKind.PropertyAssignment: {
|
||||
compiler.compileExpression((<ts.PropertyAssignment>prop.getValue()).initializer);
|
||||
pandaGen.storeOwnProperty(prop.getValue(), objReg, keyReg);
|
||||
let nameSetting: boolean = needSettingName((<ts.PropertyAssignment>prop.getValue()).initializer);
|
||||
pandaGen.storeOwnProperty(prop.getValue(), objReg, keyReg, nameSetting);
|
||||
break;
|
||||
}
|
||||
case ts.SyntaxKind.MethodDeclaration: {
|
||||
createMethodOrAccessor(pandaGen, compiler, objReg, <ts.MethodDeclaration>prop.getValue());
|
||||
pandaGen.storeOwnProperty(prop.getValue(), objReg, keyReg);
|
||||
pandaGen.storeOwnProperty(prop.getValue(), objReg, keyReg, true);
|
||||
break;
|
||||
}
|
||||
case ts.SyntaxKind.GetAccessor: {
|
||||
@@ -265,12 +267,15 @@ function setUncompiledProperties(compiler: Compiler, pandaGen: PandaGen, propert
|
||||
}
|
||||
case PropertyKind.Constant:
|
||||
case PropertyKind.Variable: {
|
||||
let nameSetting: boolean = false;
|
||||
if (ts.isMethodDeclaration(prop.getValue())) {
|
||||
createMethodOrAccessor(pandaGen, compiler, objReg, <ts.MethodDeclaration>prop.getValue());
|
||||
} else {
|
||||
compiler.compileExpression(<ts.Expression | ts.Identifier>prop.getValue());
|
||||
nameSetting = needSettingName(<ts.Expression | ts.Identifier>prop.getValue())
|
||||
&& (<string | number>(prop.getName())).toString().lastIndexOf('.') != -1;
|
||||
}
|
||||
pandaGen.storeOwnProperty(prop.getValue().parent, objReg, <string | number>(prop.getName()));
|
||||
pandaGen.storeOwnProperty(prop.getValue().parent, objReg, <string | number>(prop.getName()), nameSetting);
|
||||
break;
|
||||
}
|
||||
case PropertyKind.Prototype: {
|
||||
@@ -294,4 +299,19 @@ export function createMethodOrAccessor(pandaGen: PandaGen, compiler: Compiler, o
|
||||
} else {
|
||||
pandaGen.defineMethod(func, internalName, objReg, env);
|
||||
}
|
||||
}
|
||||
|
||||
function needSettingName(node: ts.Node): boolean {
|
||||
let tempNode: ts.Node = node;
|
||||
if (ts.isParenthesizedExpression(node)) {
|
||||
tempNode = findInnerExprOfParenthesis(node);
|
||||
}
|
||||
|
||||
if (ts.isFunctionLike(tempNode) || ts.isClassLike(tempNode)) {
|
||||
let funcOrClassNode = <ts.FunctionLikeDeclaration | ts.ClassLikeDeclaration>tempNode;
|
||||
if (!funcOrClassNode.name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -480,7 +480,7 @@ export class PandaGen {
|
||||
}
|
||||
}
|
||||
|
||||
storeOwnProperty(node: ts.Node | NodeKind, obj: VReg, prop: VReg | string | number) {
|
||||
storeOwnProperty(node: ts.Node | NodeKind, obj: VReg, prop: VReg | string | number, nameSetting: boolean = false) {
|
||||
switch (typeof prop) {
|
||||
case "number": {
|
||||
if (isInteger(prop)) {
|
||||
@@ -495,16 +495,16 @@ export class PandaGen {
|
||||
storeAccumulator(propReg),
|
||||
loadAccumulator(valueReg)
|
||||
);
|
||||
this.stOwnByValue(node, obj, propReg);
|
||||
this.stOwnByValue(node, obj, propReg, nameSetting);
|
||||
this.freeTemps(valueReg, propReg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "string":
|
||||
this.stOwnByName(node, obj, prop);
|
||||
this.stOwnByName(node, obj, prop, nameSetting);
|
||||
break;
|
||||
default:
|
||||
this.stOwnByValue(node, obj, prop);
|
||||
this.stOwnByValue(node, obj, prop, nameSetting);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,19 +551,16 @@ export class PandaGen {
|
||||
)
|
||||
}
|
||||
|
||||
private stOwnByName(node: ts.Node | NodeKind, obj: VReg, string_id: string) {
|
||||
this.add(node, storeOwnByName(obj, string_id));
|
||||
private stOwnByName(node: ts.Node | NodeKind, obj: VReg, string_id: string, nameSetting: boolean) {
|
||||
this.add(node, storeOwnByName(obj, string_id, nameSetting));
|
||||
}
|
||||
|
||||
private stOwnByIndex(node: ts.Node | NodeKind, obj: VReg, index: number) {
|
||||
this.add(
|
||||
node,
|
||||
storeOwnByIndex(obj, index)
|
||||
)
|
||||
this.add(node, storeOwnByIndex(obj, index));
|
||||
}
|
||||
|
||||
private stOwnByValue(node: ts.Node | NodeKind, obj: VReg, value: VReg) {
|
||||
this.add(node, storeOwnByValue(obj, value));
|
||||
private stOwnByValue(node: ts.Node | NodeKind, obj: VReg, value: VReg, nameSetting: boolean) {
|
||||
this.add(node, storeOwnByValue(obj, value, nameSetting));
|
||||
}
|
||||
|
||||
// eg. print
|
||||
|
||||
@@ -561,7 +561,7 @@ function compileComputedProperty(compiler: Compiler, prop: Property, classReg: V
|
||||
let protoReg = pandaGen.getTemp();
|
||||
let tmpReg = pandaGen.getTemp();
|
||||
let flag = createClassMethodOrAccessor(compiler, classReg, protoReg, tmpReg, <ts.MethodDeclaration>prop.getValue());
|
||||
pandaGen.storeOwnProperty(prop.getValue(), flag ? protoReg : classReg, keyReg);
|
||||
pandaGen.storeOwnProperty(prop.getValue(), flag ? protoReg : classReg, keyReg, true);
|
||||
pandaGen.freeTemps(protoReg, tmpReg);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user