From f7d3a584477cc5758ffa4e29b1748e7444a15b02 Mon Sep 17 00:00:00 2001 From: huangyu Date: Mon, 17 Oct 2022 17:53:34 +0800 Subject: [PATCH] Distinguish Getter/Setter from general functions Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5W3HB Signed-off-by: huangyu Change-Id: I69463d3746f161025e4dfd4e04b134857af9817b --- .../expect/types/rest/objectRestParameter.txt | 2 +- ts2panda/src/base/typeSystem.ts | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/testTs/expect/types/rest/objectRestParameter.txt b/testTs/expect/types/rest/objectRestParameter.txt index d3582019b9..f1d5ac1eb9 100644 --- a/testTs/expect/types/rest/objectRestParameter.txt +++ b/testTs/expect/types/rest/objectRestParameter.txt @@ -3,7 +3,7 @@ {'lb': [{'t': 2, 'v': 1}, {'t': 2, 'v': 0}, {'t': 25, 'v': 0}, {'t': 2, 'v': 0}, {'t': 2, 'v': 0}, {'t': 2, 'v': 2}, {'t': 5, 'v': 'm'}, {'t': 24, 'v': '_4'}, {'t': 5, 'v': 'p'}, {'t': 24, 'v': '_6'}, {'t': 2, 'v': 0}, {'t': 2, 'v': 0}], 'k': '_3'} {'lb': [{'t': 2, 'v': 3}, {'t': 2, 'v': 0}, {'t': 5, 'v': 'm'}, {'t': 2, 'v': 0}, {'t': 2, 'v': 1}, {'t': 24, 'v': '_5'}, {'t': 25, 'v': 3}], 'k': '_4'} {'lb': [{'t': 2, 'v': 6}, {'t': 2, 'v': 2}, {'t': 5, 'v': 'a'}, {'t': 25, 'v': 1}, {'t': 5, 'v': 'b'}, {'t': 25, 'v': 4}], 'k': '_5'} -{'lb': [{'t': 2, 'v': 3}, {'t': 2, 'v': 0}, {'t': 5, 'v': 'p'}, {'t': 2, 'v': 0}, {'t': 2, 'v': 1}, {'t': 24, 'v': '_7'}, {'t': 25, 'v': 0}], 'k': '_6'} +{'lb': [{'t': 2, 'v': 3}, {'t': 2, 'v': 32}, {'t': 5, 'v': 'p'}, {'t': 2, 'v': 0}, {'t': 2, 'v': 1}, {'t': 24, 'v': '_7'}, {'t': 25, 'v': 0}], 'k': '_6'} {'lb': [{'t': 2, 'v': 6}, {'t': 2, 'v': 2}, {'t': 5, 'v': 'a'}, {'t': 25, 'v': 1}, {'t': 5, 'v': 'b'}, {'t': 25, 'v': 4}], 'k': '_7'} {'lb': [{'t': 2, 'v': 2}, {'t': 24, 'v': '_3'}], 'k': '_8'} {'lb': [{'t': 2, 'v': 3}, {'t': 2, 'v': 0}, {'t': 5, 'v': 'foobar'}, {'t': 2, 'v': 0}, {'t': 2, 'v': 1}, {'t': 25, 'v': 0}, {'t': 25, 'v': 0}], 'k': '_9'} diff --git a/ts2panda/src/base/typeSystem.ts b/ts2panda/src/base/typeSystem.ts index cc06969f49..331e4f9ded 100644 --- a/ts2panda/src/base/typeSystem.ts +++ b/ts2panda/src/base/typeSystem.ts @@ -129,9 +129,9 @@ export enum ModifierAbstract { } export enum Modifier { - STATIC = 4, - ASYNC = 8, - ASTERISK = 16 + STATIC = 1 << 2, + ASYNC = 1 << 3, + ASTERISK = 1 << 4 } export enum ModifierReadonly { @@ -145,6 +145,11 @@ export enum AccessFlag { PROTECTED } +export enum GetOrSetAccessorFlag { + FALSE = 0, // Not GetAccessor and SetAccessor + TRUE = 1 << 5 // GetAccessor or SetAccessor +} + type ClassMemberFunction = ts.MethodDeclaration | ts.ConstructorDeclaration | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration; @@ -515,12 +520,16 @@ export class FunctionType extends BaseType { returnType: number = PrimitiveType.ANY; typeIndex: number; shiftedTypeIndex: number; + getOrSetAccessorFlag: GetOrSetAccessorFlag = GetOrSetAccessorFlag.FALSE; constructor(funcNode: ts.FunctionLikeDeclaration | ts.MethodSignature, builtinTypeIdx: number = undefined) { super(); let res = this.calculateIndex(builtinTypeIdx); this.typeIndex = res.typeIndex; this.shiftedTypeIndex = res.shiftedTypeIndex; + if (funcNode.kind == ts.SyntaxKind.GetAccessor || funcNode.kind == ts.SyntaxKind.SetAccessor) { + this.getOrSetAccessorFlag = GetOrSetAccessorFlag.TRUE; + } // record type before its initialization, so its index can be recorded // in case there's recursive reference of this type @@ -600,7 +609,7 @@ export class FunctionType extends BaseType { let funcTypeBuf = new LiteralBuffer(); let funcTypeLiterals: Array = new Array(); funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.FUNCTION)); - funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.accessFlag + this.modifiers)); + funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.accessFlag + this.modifiers + this.getOrSetAccessorFlag)); funcTypeLiterals.push(new Literal(LiteralTag.STRING, this.name)); if (this.containThisParam) { funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, 1)); // marker for having 'this' param -- Gitee