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 #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/class_linker.h"
22 #include "runtime/include/runtime.h"
23
24 namespace panda {
25
GetName() const26 panda_file::File::StringData Field::GetName() const
27 {
28 panda_file::FieldDataAccessor fda(*panda_file_, file_id_);
29 return panda_file_->GetStringData(fda.GetNameId());
30 }
31
ResolveTypeClass(ClassLinkerErrorHandler * error_handler) const32 Class *Field::ResolveTypeClass(ClassLinkerErrorHandler *error_handler) const
33 {
34 panda_file::FieldDataAccessor fda(*panda_file_, file_id_);
35 auto *class_linker = Runtime::GetCurrent()->GetClassLinker();
36
37 LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(*class_);
38 auto *ext = class_linker->GetExtension(ctx);
39 ASSERT(ext != nullptr);
40
41 switch (type_.GetId()) {
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::File::EntityId(fda.GetType()), class_->GetLoadContext(),
68 error_handler);
69 default:
70 UNREACHABLE();
71 };
72 }
73
74 } // namespace panda
75