forked from coolsidd/Compiler-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_expression.h
68 lines (49 loc) · 1.91 KB
/
type_expression.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Group 36
2017B4A70495P Manan Soni
2017B4A70549P Siddharth Singh
2017B4A70636P Nayan Khanna
2017B4A70740P Aditya Tulsyan
*/
#ifndef TYPE_EXP_H
#define TYPE_EXP_H
#include "primitive_type.h"
#include "rect_array_type.h"
#include "jagged_array_type.h"
#include "hash_map.h"
#define MAX_BUFFER_SIZE 400
// typedef enum {PRIMITIVE_TYPE, RECT_ARRAY, JAGGED_ARRAY} VariableType;
typedef enum {PRIMITIVE_TYPE, RECT_ARRAY, JAGGED_ARRAY} VariableType;
typedef union ____UNION_TO_BE_NAMED____ union_to_be_named;
union ____UNION_TO_BE_NAMED____{
t_primitive_type primitive_data;
rect_array_type rect_array_data;
jagged_array_type jagged_array_data;
};
typedef struct ____TYPE_EXPRESSION____ type_expression;
struct ____TYPE_EXPRESSION____{
bool is_declared;
VariableType variable_type; // to keep or not? I thought of keeping it as a Tag/Discriminator for Union
union_to_be_named union_to_be_named;
};
/* Function Prototypes */
//Return sample type expression for integer type
type_expression *get_integer_type();
//Return sample type expression for real type
type_expression *get_real_type();
//Return sample type expression for bool type
type_expression *get_bool_type();
char *get_str_primitive_type(t_primitive_type primitive_data);
void print_type_expression(type_expression *tp);
// get Printable type for assert_debug
char *str_type(type_expression *txp);
// construct type_expression given the values for reqd fields
// called only through declarative statements of a variable
// how would we pass the fields?
type_expression *construct_type_expression(VariableType variable_type, union_to_be_named union_ds);
// get the desired String Representation of TypeExpression
char* get_string_representation(type_expression* tp);
// set is_declared to true on encountering decl_stmt
void set_declare_flag(type_expression* tp);
union_to_be_named *populate_union(VariableType variable_type, Parse_tree_node *p);
#endif