1/* 2 * Copyright (c) 2021 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 NULLVALUE = 255 26} 27 28export class Literal { 29 private t: LiteralTag; 30 private v: any; 31 32 constructor(t: LiteralTag, v: any) { 33 this.t = t; 34 this.v = v; 35 } 36 37 getTag() { 38 return this.t; 39 } 40 41 getValue() { 42 return this.v; 43 } 44} 45 46export class LiteralBuffer { 47 private lb: Literal[] = []; 48 49 constructor() { }; 50 51 addLiterals(...literals: Array<Literal>) { 52 this.lb.push(...literals); 53 } 54 55 getLiterals() { 56 return this.lb; 57 } 58 59 isEmpty() { 60 return this.lb.length == 0; 61 } 62 63 getLiteral(index: number) { 64 if (index >= this.lb.length || this.lb.length <=0) { 65 return ; 66 } 67 return this.lb[index]; 68 } 69}