DEADSOFTWARE

...
[mp3cc.git] / MPC.3.5.LINUX / structures / identifier.h
1 /********************************************************************
3 identifier.h - structures used to hold identifier descriptions
5 Niksa Orlic, 2004-04-28
7 ********************************************************************/
9 /*
10 When an unit compiles, it exports public symbols into
12 unit_name.bsf (binary symbol file)
14 The bsf file contains an array of symbol entries.
16 Symbols are divided into the following categories:
18 Constant
19 ---------
20 1 byte identifier: set to 1 to indicate that it is an constant
21 STRING - symbol name
22 1 byte to indicate the constant type, (1-integer, 2-real, 3-boolean, 4-char, 5-string)
23 value: if a constant is integer or float, this is 4-byte field
24 if a constant is string, then a STRING entry follows
25 if a constant is a boolean or a char, 1 byte follows
27 Variable
28 --------
29 1 byte indentifier: set to 2 for variable
30 STRING - symbol name
31 TYPE - variable type
33 Type
34 ----
35 1 byte identifier: set to 3 for type definition
36 STRING - symbol name
37 TYPE - the type description
39 Procedure
40 ---------
41 1 byte identifier: set to 4 for procedures
42 STRING - name
43 1 byte - the number of parameters (n)
44 TYPE[n] - parameters type
46 Function
47 --------
48 1 byte identifier: set to 5 for functions
49 STRING - name
50 TYPE - return type
51 1 byte - number of parameters
52 TYPE[n] - parameter types
55 Special fields used are:
57 STRING
58 ------
59 1 byte containing the string length (n)
60 n bytes with the string data (NOT zero terminated)
62 TYPE
63 ----
64 1 byte : type class, a value from en_type_class enumeration
66 if a type is an array: TYPE element_type
67 1 byte dimensions num
68 TYPE[n] dimension interval types
70 if a type is a record: 1 byte number of elements
71 {STRING, TYPE} [n] for each element there is a pair name/type describing the member
72 4 bytes record ID
74 if a type is an interval: 1 byte interval base type (from the en_type_class)
75 4 bytes: starting value
76 4 bytes: ending value
78 */
80 #include <stdio.h>
82 /*
83 The possible identifier classes
84 */
85 enum en_identifier_class
86 {
87 none,
88 program_name,
89 constant_name,
90 variable_name,
91 type_name,
92 procedure_name,
93 function_name,
94 parameter_name,
95 unit_name
96 };
99 /*
100 The structure used to hold the description of
101 a single identifier
102 */
103 struct identifier_descriptor_struct
105 enum en_identifier_class identifier_class;
107 /* for constants */
108 type *constant_type;
109 int constant_int_value;
110 float constant_real_value;
111 string *constant_string_value;
113 /* for variables */
114 type *variable_type;
115 int variable_index;
117 /* for types */
118 type *defined_type;
120 /* for procedures and functions */
121 type *return_type;
122 type_list *parameters; /* the list of formal parameters to the function, each one is identifier_descriptor */
123 type_list *variables; /* the list of names of variables */
124 int forward_declaration;
125 int standard_function;
126 int subprogram_linenum; /* the number of the first line of the subprogram */
127 int unit_function; /* used by all items that are defined inside an unit , 1 says that the item is inside a unit */
128 struct unit_struct *container_unit;
130 /* for parameters */
131 type *parameter_type;
132 short int is_parameter_variable;
133 int parameter_index;
135 /* for units */
136 struct unit_struct *unit_block;
138 /* this field is set in get_identifier function and is true
139 if this struct describes identifier directly located inside
140 the program block*/
141 int belongs_to_program_block;
142 };
145 typedef struct identifier_descriptor_struct identifier;
147 identifier *identifier_create();
148 void identifier_destroy(identifier*);
149 identifier *identifier_duplicate(identifier*);
151 struct type_struct;
152 struct string_list_struct;
153 struct string_struct;
155 void bsf_write_integer_constant(long int value, char* name);
156 void bsf_write_real_constant(float value, char* name);
157 void bsf_write_boolean_constant(char value, char* name);
158 void bsf_write_char_constant(char value, char* name);
159 void bsf_write_string_constant(string* value, char* name);
160 void bsf_write_variables(struct string_list_struct* names, struct type_struct* var_type);
161 void bsf_write_type(string* type_name, struct type_struct* type_type);
162 void bsf_write_procedure(string* name, type_list* parameters);
163 void bsf_write_function(string* name, type_list* parameters, type* return_type);
164 void bsf_write_STRING(char* value);
165 void bsf_write_TYPE(type* type_desc);
167 struct string_struct* bsf_read_STRING(FILE*);
168 struct type_struct* bsf_read_TYPE(FILE*);