• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16export enum LiteralTag {
17    BOOLEAN = 1,
18    INTEGER = 2,
19    DOUBLE = 4,
20    STRING = 5,
21    METHOD = 6,
22    GENERATOR = 7,
23    ACCESSOR = 8,
24    METHODAFFILIATE = 9,
25    // 0x0a - 0x15 for ARRAY_Type
26    ASYNCGENERATOR = 22,
27    LITERALBUFFERINDEX = 23,
28    LITERALARRAY = 24,
29    BUILTINTYPEINDEX = 25,
30    NULLVALUE = 255
31}
32
33export class Literal {
34    private t: LiteralTag;
35    private v: any;
36
37    constructor(t: LiteralTag, v: any) {
38        this.t = t;
39        this.v = v;
40    }
41
42    getTag(): LiteralTag {
43        return this.t;
44    }
45
46    getValue(): any {
47        return this.v;
48    }
49}
50
51export class LiteralBuffer {
52    private k: string;
53    private lb: Literal[] = [];
54
55    constructor() {};
56
57    addLiterals(...literals: Array<Literal>) {
58        this.lb.push(...literals);
59    }
60
61    getLiterals(): Literal[] {
62        return this.lb;
63    }
64
65    isEmpty(): boolean {
66        return this.lb.length === 0;
67    }
68
69    getLiteral(index: number): Literal {
70        if (index >= this.lb.length || this.lb.length <=0) {
71        return ;
72        }
73        return this.lb[index];
74    }
75
76    setKey(key: string): void {
77        this.k = key;
78    }
79}
80