• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef ECMASCRIPT_MESSAGE_STRING_H
17 #define ECMASCRIPT_MESSAGE_STRING_H
18 
19 #include <string>
20 
21 #include "ecmascript/compiler/builtins/builtins_stubs.h"
22 #include "ecmascript/compiler/common_stubs.h"
23 #include "ecmascript/compiler/interpreter_stub.h"
24 
25 namespace panda::ecmascript {
26 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
27 #define COMMON_MESSAGE_STRING_LIST(V)                                                        \
28     V(SetReadOnlyProperty, "Cannot set readonly property")                                   \
29     V(FunctionCallNotConstructor, "class constructor cannot call")                           \
30     V(SetPropertyWhenNotExtensible, "Cannot add property in prevent extensions ")            \
31     V(GetPropertyOutOfBounds, "Get Property index out-of-bounds")                            \
32     V(CanNotSetPropertyOnContainer, "Cannot set property on Container")                      \
33     V(NonCallable, "CallObj is NonCallable")                                                 \
34     V(ASM_INTERPRETER_STUB_NAME, "ASM_INTERPRETER stub name: ")                              \
35     V(OPCODE_OVERFLOW, "opcode overflow!")                                                   \
36     V(INT32_VALUE, "value: %ld")                                                             \
37     V(TargetTypeNotObject, "Type of target is not Object")                                   \
38     V(CanNotGetNotEcmaObject, "Can not get Prototype on non ECMA Object")                    \
39     V(InstanceOfErrorTargetNotCallable, "InstanceOf error when target is not Callable")
40 
41 #define DEBUG_CHECK_MESSAGE_STRING_LIST(V)                                                   \
42     V(IsCallable)                                                                            \
43     V(LoadHClass)                                                                            \
44     V(IsDictionaryMode)                                                                      \
45     V(IsClassConstructor)                                                                    \
46     V(IsClassPrototype)                                                                      \
47     V(IsExtensible)                                                                          \
48     V(IsEcmaObject)                                                                          \
49     V(IsJSObject)                                                                            \
50     V(IsString)                                                                              \
51     V(IsJSHClass)                                                                            \
52     V(IsNotDictionaryMode)
53 
54 class MessageString {
55 public:
56     enum MessageId {
57     // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
58 #define DEF_MESSAGE_ID(name, string) Message_##name,
59         COMMON_MESSAGE_STRING_LIST(DEF_MESSAGE_ID)
60 #undef DEF_MESSAGE_ID
61 #define DEF_MESSAGE_ID(name) Message_##name,
62         ASM_INTERPRETER_BC_STUB_LIST(DEF_MESSAGE_ID, DEF_MESSAGE_ID, DEF_MESSAGE_ID)
63         ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_MESSAGE_ID)
64         ASM_INTERPRETER_BC_HELPER_STUB_LIST(DEF_MESSAGE_ID)
65         BUILTINS_STUB_LIST(DEF_MESSAGE_ID)
66         RUNTIME_ASM_STUB_LIST(DEF_MESSAGE_ID)
67         DEBUG_CHECK_MESSAGE_STRING_LIST(DEF_MESSAGE_ID)
68 #undef DEF_MESSAGE_ID
69         MAX_MESSAGE_COUNT,
70         ASM_INTERPRETER_START = Message_INT32_VALUE + 1,
71         BUILTINS_STUB_START = Message_CharCodeAt,
72         BUILTINS_STUB_LAST = Message_ArrayConstructor,
73     };
74     static const std::string& GetMessageString(int id);
75 
IsBuiltinsStubMessageString(int id)76     static bool IsBuiltinsStubMessageString(int id)
77     {
78         return (id >= BUILTINS_STUB_START) && (id <= BUILTINS_STUB_LAST);
79     }
80 };
81 
82 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
83 #define GET_MESSAGE_STRING_ID(name) static_cast<int>((MessageString::MessageId::Message_##name))
84 }  // namespace panda::ecmascript
85 #endif  // ECMASCRIPT_MESSAGE_STRING_H
86