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#ifndef ASSEMBLER_ASSEMBLY_RECORD_H
17#define 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
28namespace panda::pandasm {
29
30struct Record {
31    std::string name = "";
32    bool conflict = false; /* Name is conflict with panda primitive types. Need special handle. */
33    panda::panda_file::SourceLang language;
34    std::unique_ptr<RecordMetadata> metadata;
35    std::vector<Field> field_list; /* class fields list */
36    size_t params_num = 0;
37    bool body_presence = false;
38    SourceLocation body_location;
39    std::string source_file; /* The file in which the record is defined or empty */
40    std::optional<FileLocation> file_location;
41
42    Record(std::string s, panda::panda_file::SourceLang lang, size_t b_l, size_t b_r, std::string f_c, bool d,
43           size_t l_n)
44        : name(std::move(s)),
45          language(lang),
46          metadata(extensions::MetadataExtension::CreateRecordMetadata(lang)),
47          file_location({f_c, b_l, b_r, l_n, d})
48    {
49        metadata->SetAccessFlags(panda::ACC_PUBLIC);
50    }
51
52    Record(std::string s, panda::panda_file::SourceLang lang)
53        : name(std::move(s)), language(lang), metadata(extensions::MetadataExtension::CreateRecordMetadata(lang))
54    {
55        metadata->SetAccessFlags(panda::ACC_PUBLIC);
56    }
57
58    bool HasImplementation() const
59    {
60        return !metadata->IsForeign();
61    }
62};
63
64}  // namespace panda::pandasm
65
66#endif  // ASSEMBLER_ASSEMBLY_RECORD_H
67