Bash++
Bash++ compiler internal documentation
bpp_entity.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Andrew S. Rightenburg
3 * Bash++: Bash with classes
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7#pragma once
8
9#include <string>
10#include <memory>
11#include <vector>
12#include <list>
13
14#include "bpp.h"
15
16namespace bpp {
17
26 protected:
27 std::string name;
28
29 OwnedEntityList<bpp_object> local_objects; // Objects owned by this entity
32
33 std::weak_ptr<bpp_class> type;
34 std::weak_ptr<bpp_class> containing_class;
35 std::weak_ptr<bpp_program> containing_program;
36
38 std::vector<std::weak_ptr<bpp_class>> parents;
39
41 std::weak_ptr<bpp_entity> parent_entity;
42
43 std::weak_ptr<bpp_method> overridden_method;
45 std::list<bpp::SymbolPosition> references;
46 public:
47 bpp_entity() = default;
48 virtual ~bpp_entity() = default;
49
50 bpp_entity(const bpp_entity& other) = default;
51 bpp_entity& operator=(const bpp_entity& other) = default;
52 bpp_entity(bpp_entity&& other) noexcept = default;
53 bpp_entity& operator=(bpp_entity&& other) noexcept = default;
54
55 virtual bool add_object(std::shared_ptr<bpp_object> object, bool make_local = false);
56
57 virtual std::shared_ptr<bpp_class> get_class();
58 virtual std::string get_address() const;
59 virtual void set_name(const std::string& name);
60 virtual std::string get_name() const;
61 virtual std::weak_ptr<bpp::bpp_class> get_containing_class();
62 virtual std::weak_ptr<bpp_program> get_containing_program();
63 virtual bool set_containing_class(std::weak_ptr<bpp::bpp_class> containing_class);
64
65 void inherit(std::shared_ptr<bpp_entity> parent);
66 void inherit(std::shared_ptr<bpp_program> program);
67 virtual void inherit(std::shared_ptr<bpp_class> parent);
68
69 void set_definition_position(const std::string& file, uint64_t line, uint64_t column);
70 void add_reference(const std::string& file, uint64_t line, uint64_t column);
71
73 std::list<bpp::SymbolPosition> get_references() const;
74
75 virtual std::shared_ptr<bpp_class> get_class(const std::string& name, size_t max_visible_index = SIZE_MAX);
76 std::shared_ptr<bpp_object> get_object(const std::string& name, size_t max_visible_index = SIZE_MAX);
77
78 virtual std::vector<std::shared_ptr<bpp_class>> get_all_known_classes() const;
79 virtual std::vector<std::shared_ptr<bpp_object>> get_all_known_objects() const;
80
82
83 std::shared_ptr<bpp_class> get_parent() const;
84
85 size_t number_of_known_objects() const;
86 virtual size_t number_of_known_classes() const;
87};
88
89} // namespace bpp
Definition bpp.h:151
The base class for all entities in the Bash++ compiler.
Definition bpp_entity.h:25
virtual size_t number_of_known_classes() const
Definition bpp_entity.cpp:177
std::shared_ptr< bpp_class > get_parent() const
Definition bpp_entity.cpp:161
size_t number_of_known_objects() const
Definition bpp_entity.cpp:169
bpp_entity()=default
std::weak_ptr< bpp_class > type
Definition bpp_entity.h:33
virtual void set_name(const std::string &name)
Definition bpp_entity.cpp:38
virtual std::weak_ptr< bpp::bpp_class > get_containing_class()
Get the class which contains this entity.
Definition bpp_entity.cpp:51
std::shared_ptr< bpp_object > get_object(const std::string &name, size_t max_visible_index=SIZE_MAX)
Definition bpp_entity.cpp:120
std::string name
Definition bpp_entity.h:27
virtual std::vector< std::shared_ptr< bpp_object > > get_all_known_objects() const
Definition bpp_entity.cpp:145
virtual bool add_object(std::shared_ptr< bpp_object > object, bool make_local=false)
Add an object to this entity's list of objects.
Definition bpp_entity.cpp:22
virtual ~bpp_entity()=default
bpp_entity & operator=(bpp_entity &&other) noexcept=default
OwnedEntityList< bpp_object > local_objects
Definition bpp_entity.h:29
std::vector< std::weak_ptr< bpp_class > > parents
For classes: the list of parent classes, in order.
Definition bpp_entity.h:38
void add_reference(const std::string &file, uint64_t line, uint64_t column)
Definition bpp_entity.cpp:73
bpp::SymbolPosition get_initial_definition() const
Definition bpp_entity.cpp:69
bpp_entity(const bpp_entity &other)=default
std::weak_ptr< bpp_entity > parent_entity
For all entities (except program), the parent entity from which this entity inherits.
Definition bpp_entity.h:41
std::weak_ptr< bpp_program > containing_program
Definition bpp_entity.h:35
virtual std::weak_ptr< bpp_program > get_containing_program()
Definition bpp_entity.cpp:55
std::weak_ptr< bpp_method > overridden_method
Definition bpp_entity.h:43
size_t parent_visible_object_count_at_creation
Definition bpp_entity.h:30
virtual std::string get_address() const
Definition bpp_entity.cpp:34
std::list< bpp::SymbolPosition > references
Definition bpp_entity.h:45
virtual std::vector< std::shared_ptr< bpp_class > > get_all_known_classes() const
Definition bpp_entity.cpp:135
const OwnedEntityList< bpp_object > & get_local_objects() const
Definition bpp_entity.cpp:131
std::weak_ptr< bpp_class > containing_class
Definition bpp_entity.h:34
virtual bool set_containing_class(std::weak_ptr< bpp::bpp_class > containing_class)
Definition bpp_entity.cpp:59
virtual std::string get_name() const
Definition bpp_entity.cpp:42
size_t program_visible_class_count_at_creation
Definition bpp_entity.h:31
std::list< bpp::SymbolPosition > get_references() const
Definition bpp_entity.cpp:84
void inherit(std::shared_ptr< bpp_entity > parent)
Inherit from a parent entity.
Definition bpp_entity.cpp:93
void set_definition_position(const std::string &file, uint64_t line, uint64_t column)
Definition bpp_entity.cpp:64
bpp_entity(bpp_entity &&other) noexcept=default
bpp_entity & operator=(const bpp_entity &other)=default
virtual std::shared_ptr< bpp_class > get_class()
Definition bpp_entity.cpp:30
bpp::SymbolPosition initial_definition
Definition bpp_entity.h:44
Definition bash_case.cpp:9
Definition bpp.h:140