1e41f4b71Sopenharmony_ci# Naming Rules of Ark Bytecode Functions
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Introduction
4e41f4b71Sopenharmony_ciThis topic describes the naming rule of the string pointed by the **name_off** field of [Method](arkts-bytecode-file-format.md#method) in the bytecode file. The naming rule takes effect since the Ark Bytecode file version **12.0.4.0**.
5e41f4b71Sopenharmony_ci## Entrypoint Function
6e41f4b71Sopenharmony_ciFunction that is executed when the module is loaded. The function name is fixed to **func_main_0**.
7e41f4b71Sopenharmony_ci## Non-entrypoint Function
8e41f4b71Sopenharmony_ciThe name structure of other functions in the bytecode file is as follows:
9e41f4b71Sopenharmony_ci```ts
10e41f4b71Sopenharmony_ci##Prefix#Original function name
11e41f4b71Sopenharmony_ci```
12e41f4b71Sopenharmony_ciThe following sections describe the prefix and original function name in detail.
13e41f4b71Sopenharmony_ci### Prefix
14e41f4b71Sopenharmony_ciThe prefix contains the scope information when the function is defined. It consists of the following parts:
15e41f4b71Sopenharmony_ci* Scope label
16e41f4b71Sopenharmony_ci* Scope name
17e41f4b71Sopenharmony_ci* Duplicate sequence number
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciThe structure of the prefix is as follows:
20e41f4b71Sopenharmony_ci```ts
21e41f4b71Sopenharmony_ci<Scope Label 1><Scope Name 1>[<Duplicate Sequence Number>]<Scope Label 2><Scope Name 2><[Duplicate Sequence Number]>...<Scope Label n><Scope Name n>[<Duplicate Sequence Number >]<Scope Label n+1>
22e41f4b71Sopenharmony_ci```
23e41f4b71Sopenharmony_ciIn this case, angle brackets (< >) are separators for easy reading and are excluded from the actual prefix; square brackets ([ ]) indicate that the value can be empty. [\<Duplicate Sequence Number>] is required only when duplicate scope names exist. That is, [\<Duplicate sequence number>] can be empty. The last scope label is the label corresponding to the function.
24e41f4b71Sopenharmony_ci#### Scope Label
25e41f4b71Sopenharmony_ciThe scope label indicates the type of the scope. The following table lists the scopes and corresponding labels. Other scopes are not recorded in the function name.
26e41f4b71Sopenharmony_ci| Scope | Scope Label | Description |
27e41f4b71Sopenharmony_ci| --- | --- | --- |
28e41f4b71Sopenharmony_ci| Class | `~` | Scope defined by the **class** keyword. |
29e41f4b71Sopenharmony_ci| Instance function | `>` | Scope defined by the instance function of a class |
30e41f4b71Sopenharmony_ci| Static function | `<` | Scope defined by the static function of a class |
31e41f4b71Sopenharmony_ci| Constructor | `=` | Scope defined by the constructor of a class |
32e41f4b71Sopenharmony_ci| Common function | `*` | Scopes defined by all functions except the preceding types |
33e41f4b71Sopenharmony_ci| namespace/module | `&` | Scope defined by the **namespace** or **module** keyword |
34e41f4b71Sopenharmony_ci| enum | `%` | Scope defined by the **enum** keyword |
35e41f4b71Sopenharmony_ci#### Scope Name
36e41f4b71Sopenharmony_ciThe name used to define the scope in the source code. If the value is anonymous, the value is an empty string. To reduce the bytecode size, the ArkCompiler optimizes long scope names. In this case, the scope names are displayed in the format of **@hexadecimal number**. The number indicates the index of the string of the scope name in a string array. In the bytecode file, there is a [field](arkts-bytecode-file-format.md#field), field named **ScopeNames** in the [Class](arkts-bytecode-file-format.md#class) corresponding to the source code. The value of this **field** points to an offset of [LiteralArray](arkts-bytecode-file-format.md#literalarray). This **LiteralArray** stores a string array. The hexadecimal number is the index of the scope name in this array. The original function name is not converted to an index.
37e41f4b71Sopenharmony_ciExample:
38e41f4b71Sopenharmony_ci```ts
39e41f4b71Sopenharmony_cifunction longFuncName() {                  // The function name of longFuncName is "#*#longFuncName", in which "longFuncName" is the original function name and will not be converted to an index.
40e41f4b71Sopenharmony_ci    function A() { }                       // The function name of A is "#*@0*#A", where "@0" indicates the string whose index is 0 in the corresponding LiteralArray. In this case, the string is "longFuncName". That is, the original name of the function is "#*longFuncName*#A".
41e41f4b71Sopenharmony_ci    function B() { }                       // Thefunction name of B is "#*@0*#B".
42e41f4b71Sopenharmony_ci}  
43e41f4b71Sopenharmony_ci```
44e41f4b71Sopenharmony_ci#### Duplicate Sequence Number
45e41f4b71Sopenharmony_ciIf an entity with the same name exists in the same scope of the source code, the entity name is suffixed with a sequence number. The sequence number is in the format of **^ hexadecimal number**. If duplicate names exist, the first one is not numbered, that is, the sequence number of duplicate names is empty. The sequence is numbered from the second one, starting from **1**.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ciExample:
48e41f4b71Sopenharmony_ci```ts
49e41f4b71Sopenharmony_cinamespace A {
50e41f4b71Sopenharmony_ci    function bar() { }                      // The function name of bar is "#&A*#bar".
51e41f4b71Sopenharmony_ci}
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_cinamespace A {
54e41f4b71Sopenharmony_ci    function foo() { }                      // The function name of foo is "#&A^1*#foo", where "^1" indicates the duplicate sequence number.
55e41f4b71Sopenharmony_ci}
56e41f4b71Sopenharmony_ci```
57e41f4b71Sopenharmony_ci### Original Function Name
58e41f4b71Sopenharmony_ciThe original function name indicates the name of the function in the source code. For an anonymous function, the value is an empty string. Similarly, if a function with the same name exists in the same scope of the source code, the function name is followed by a sequence number, including an anonymous function.
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci```ts
61e41f4b71Sopenharmony_cifunction foo() {}                           // The original function name is "foo".
62e41f4b71Sopenharmony_ci() => { }                                   // The original function name is "".
63e41f4b71Sopenharmony_ci() => { }                                   // The original function name is "^1".
64e41f4b71Sopenharmony_ci```
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci#### Special Scenarios
67e41f4b71Sopenharmony_ci1. If an anonymous function is assigned a value to a variable when it is defined, the original function name is the variable name. An example is as follows:
68e41f4b71Sopenharmony_ci```ts
69e41f4b71Sopenharmony_cilet a = () => {}                            // The original function name is "a".
70e41f4b71Sopenharmony_ci```
71e41f4b71Sopenharmony_ci2. If an anonymous function is defined in an object literal and assigned to a literal attribute:
72e41f4b71Sopenharmony_ci* If the attribute name does not contain a **slash (\)** or a **period (.)**, the original function name is the attribute name.
73e41f4b71Sopenharmony_ci```ts
74e41f4b71Sopenharmony_cilet B = {
75e41f4b71Sopenharmony_ci    b : () => {}                            // The original function name is "b".
76e41f4b71Sopenharmony_ci}
77e41f4b71Sopenharmony_ci```
78e41f4b71Sopenharmony_ci* If the attribute name contains a **slash (\)** or a **period (.)**, the original function is named as an anonymous function to prevent ambiguity.
79e41f4b71Sopenharmony_ci```ts
80e41f4b71Sopenharmony_cilet a = {
81e41f4b71Sopenharmony_ci    "a.b#c^2": () => {}                     // The original function name is "".
82e41f4b71Sopenharmony_ci    "x\\y#": () => {}                       // The original function name is "^1".
83e41f4b71Sopenharmony_ci}
84e41f4b71Sopenharmony_ci```
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**You should avoid using characters other than letters, digits, and underscores (_) to name functions to avoid ambiguity.**
87e41f4b71Sopenharmony_ci## Example
88e41f4b71Sopenharmony_ci```ts
89e41f4b71Sopenharmony_cinamespace A {                               // The function name of namespace in bytecode is "#&#A".
90e41f4b71Sopenharmony_ci    class B {                               // The function name of the constructor in bytecode is "#&A~B=#B".
91e41f4b71Sopenharmony_ci        m() {                               // The function name of m in bytecode is "#&A~B>#m".
92e41f4b71Sopenharmony_ci            return () => {}                 // The function name of the anonymous function in bytecode is "#&A~B>m*#".
93e41f4b71Sopenharmony_ci        }
94e41f4b71Sopenharmony_ci        static s() {}                       // The function name of static function s in bytecode is "#&A~B<#s".
95e41f4b71Sopenharmony_ci    }
96e41f4b71Sopenharmony_ci    enum E {                                // The function name of enum in bytecode is "#&A %#E".
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci    }
99e41f4b71Sopenharmony_ci}
100e41f4b71Sopenharmony_ci```
101e41f4b71Sopenharmony_ci```ts
102e41f4b71Sopenharmony_cinamespace LongNamespaceName {               // The function name of namespace in bytecode is "#&#LongNamespaceName".
103e41f4b71Sopenharmony_ci    class LongClassName {                   // The function name of the constructor in bytecode is "#&@1~@0=#LongClassName".
104e41f4b71Sopenharmony_ci        longFunctionName() {                // The function name of the instance function in the bytecode is "#&@1~@0>#longFunctionName".
105e41f4b71Sopenharmony_ci        }
106e41f4b71Sopenharmony_ci        longFunctionName() {                // The function name in bytecode is "#&@1~@0>#longFunctionName^1".
107e41f4b71Sopenharmony_ci            function inSecondFunction() {}  // The function name in bytecode is "#&@1~@0>@2^1*#inSecondFunction".
108e41f4b71Sopenharmony_ci        }
109e41f4b71Sopenharmony_ci    }
110e41f4b71Sopenharmony_ci}
111e41f4b71Sopenharmony_ci```
112