Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1 | #ifndef T_STRUCT_H |
2 | #define T_STRUCT_H | ||||
3 | |||||
4 | #include <vector> | ||||
5 | #include <string> | ||||
6 | |||||
7 | #include "t_type.h" | ||||
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 8 | #include "t_field.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 9 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 10 | // Forward declare that puppy |
11 | class t_program; | ||||
12 | |||||
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 13 | /** |
14 | * A struct is a container for a set of member fields that has a name. Structs | ||||
15 | * are also used to implement exception types. | ||||
16 | * | ||||
17 | * @author Mark Slee <mcslee@facebook.com> | ||||
18 | */ | ||||
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 19 | class t_struct : public t_type { |
20 | public: | ||||
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 21 | t_struct(t_program* program) : |
22 | t_type(program), | ||||
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 23 | is_xception_(false) {} |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 24 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 25 | t_struct(t_program* program, const std::string& name) : |
26 | t_type(program, name), | ||||
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 27 | is_xception_(false) {} |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 28 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 29 | void set_name(const std::string& name) { |
30 | name_ = name; | ||||
31 | } | ||||
32 | |||||
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 33 | void set_xception(bool is_xception) { |
34 | is_xception_ = is_xception; | ||||
35 | } | ||||
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 36 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 37 | void append(t_field* elem) { |
38 | members_.push_back(elem); | ||||
39 | } | ||||
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 40 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 41 | const std::vector<t_field*>& get_members() { |
42 | return members_; | ||||
43 | } | ||||
44 | |||||
45 | bool is_struct() const { | ||||
46 | return !is_xception_; | ||||
47 | } | ||||
48 | |||||
49 | bool is_xception() const { | ||||
50 | return is_xception_; | ||||
51 | } | ||||
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 52 | |
53 | private: | ||||
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 54 | std::vector<t_field*> members_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 55 | bool is_xception_; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 56 | }; |
57 | |||||
58 | #endif |