1 /*
2  * Copyright (c) 2021-2024 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 PANDA_ASSEMBLER_ASSEMBLY_RECORD_H
17 #define PANDA_ASSEMBLER_ASSEMBLY_RECORD_H
18 
19 #include <memory>
20 #include <optional>
21 #include <string>
22 #include <vector>
23 
24 #include "assembly-field.h"
25 #include "extensions/extensions.h"
26 #include "ide_helpers.h"
27 
28 namespace ark::pandasm {
29 
30 // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
31 struct Record {
32     std::string name;
33     bool conflict = false; /* Name is conflict with panda primitive types. Need special handle. */
34     ark::panda_file::SourceLang language;
35     std::unique_ptr<RecordMetadata> metadata;
36     std::vector<Field> fieldList; /* class fields list */
37     size_t paramsNum = 0;
38     bool bodyPresence = false;
39     SourceLocation bodyLocation;
40     std::string sourceFile; /* The file in which the record is defined or empty */
41     std::optional<FileLocation> fileLocation;
42 
43     // CC-OFFNXT(G.FUN.01-CPP) solid logic
Recordark::pandasm::Record44     Record(std::string s, ark::panda_file::SourceLang lang, size_t bL, size_t bR, std::string fC, bool d, size_t lN)
45         : name(std::move(s)),
46           language(lang),
47           metadata(extensions::MetadataExtension::CreateRecordMetadata(lang)),
48           fileLocation({fC, bL, bR, lN, d})
49     {
50     }
51 
Recordark::pandasm::Record52     Record(std::string s, ark::panda_file::SourceLang lang)
53         : name(std::move(s)), language(lang), metadata(extensions::MetadataExtension::CreateRecordMetadata(lang))
54     {
55     }
56 
HasImplementationark::pandasm::Record57     bool HasImplementation() const
58     {
59         return !metadata->IsForeign();
60     }
61 };
62 // NOLINTEND(misc-non-private-member-variables-in-classes)
63 
64 }  // namespace ark::pandasm
65 
66 #endif  // PANDA_ASSEMBLER_ASSEMBLY_RECORD_H
67