• 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 
16 #include "runtime/include/field.h"
17 
18 #include "libpandabase/utils/hash.h"
19 #include "libpandafile/field_data_accessor.h"
20 #include "libpandafile/file-inl.h"
21 #include "runtime/include/runtime.h"
22 
23 namespace panda {
24 
GetName() const25 panda_file::File::StringData Field::GetName() const
26 {
27     const auto *panda_file = GetPandaFile();
28     auto name_id = panda_file::FieldDataAccessor::GetNameId(*panda_file, file_id_);
29     return panda_file->GetStringData(name_id);
30 }
31 
ResolveTypeClass(ClassLinkerErrorHandler * error_handler) const32 Class *Field::ResolveTypeClass(ClassLinkerErrorHandler *error_handler) const
33 {
34     const auto *panda_file = GetPandaFile();
35     auto *class_linker = Runtime::GetCurrent()->GetClassLinker();
36 
37     LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(*GetClass());
38     auto *ext = class_linker->GetExtension(ctx);
39     ASSERT(ext != nullptr);
40 
41     switch (GetTypeId()) {
42         case panda_file::Type::TypeId::U1:
43             return ext->GetClassRoot(ClassRoot::U1);
44         case panda_file::Type::TypeId::I8:
45             return ext->GetClassRoot(ClassRoot::I8);
46         case panda_file::Type::TypeId::U8:
47             return ext->GetClassRoot(ClassRoot::U8);
48         case panda_file::Type::TypeId::I16:
49             return ext->GetClassRoot(ClassRoot::I16);
50         case panda_file::Type::TypeId::U16:
51             return ext->GetClassRoot(ClassRoot::U16);
52         case panda_file::Type::TypeId::I32:
53             return ext->GetClassRoot(ClassRoot::I32);
54         case panda_file::Type::TypeId::U32:
55             return ext->GetClassRoot(ClassRoot::U32);
56         case panda_file::Type::TypeId::I64:
57             return ext->GetClassRoot(ClassRoot::I64);
58         case panda_file::Type::TypeId::U64:
59             return ext->GetClassRoot(ClassRoot::U64);
60         case panda_file::Type::TypeId::F32:
61             return ext->GetClassRoot(ClassRoot::F32);
62         case panda_file::Type::TypeId::F64:
63             return ext->GetClassRoot(ClassRoot::F64);
64         case panda_file::Type::TypeId::TAGGED:
65             return ext->GetClassRoot(ClassRoot::TAGGED);
66         case panda_file::Type::TypeId::REFERENCE:
67             return ext->GetClass(*panda_file, panda_file::FieldDataAccessor::GetTypeId(*panda_file, file_id_),
68                                  GetClass()->GetLoadContext(), error_handler);
69         default:
70             UNREACHABLE();
71     }
72 }
73 
GetPandaFile() const74 const panda_file::File *Field::GetPandaFile() const
75 {
76     return GetClass()->GetPandaFile();
77 }
78 
79 }  // namespace panda
80