equal
deleted
inserted
replaced
78 |
78 |
79 #ifndef HGVERSION |
79 #ifndef HGVERSION |
80 #define HGVERSION "" |
80 #define HGVERSION "" |
81 #endif |
81 #endif |
82 |
82 |
83 #define ERROR error_exit(__FILE__,__LINE__) |
83 #include "main.hh" // symbol_c type |
84 void error_exit(const char *file_name, int line_no) { |
84 #include <stdarg.h> // required for va_start(), va_list |
85 std::cerr << "\nInternal compiler error in file " << file_name |
85 |
86 << " at line " << line_no << "\n"; |
86 void error_exit(const char *file_name, int line_no, const char *errmsg, ...) { |
87 // if (msg != NULL) std::cerr << message << "\n\n"; |
87 va_list argptr; |
|
88 va_start(argptr, errmsg); /* second argument is last fixed pamater of error_exit() */ |
|
89 |
|
90 fprintf(stderr, "\nInternal compiler error in file %s at line %d", file_name, line_no); |
|
91 if (errmsg != NULL) { |
|
92 fprintf(stderr, ": "); |
|
93 vfprintf(stderr, errmsg, argptr); |
|
94 } else { |
|
95 fprintf(stderr, "."); |
|
96 } |
|
97 fprintf(stderr, "\n"); |
|
98 va_end(argptr); |
|
99 |
88 exit(EXIT_FAILURE); |
100 exit(EXIT_FAILURE); |
89 } |
101 } |
90 |
102 |
91 |
103 |
92 |
104 |
122 int main(int argc, char **argv) { |
134 int main(int argc, char **argv) { |
123 symbol_c *tree_root; |
135 symbol_c *tree_root; |
124 char * builddir = NULL; |
136 char * builddir = NULL; |
125 stage1_2_options_t stage1_2_options = {false, false, NULL}; |
137 stage1_2_options_t stage1_2_options = {false, false, NULL}; |
126 int optres, errflg = 0; |
138 int optres, errflg = 0; |
|
139 int path_len; |
127 /* |
140 /* |
128 extern char *optarg; |
141 extern char *optarg; |
129 extern int optind, optopt; |
142 extern int optind, optopt; |
130 */ |
143 */ |
131 |
144 |
146 break; |
159 break; |
147 case 's': |
160 case 's': |
148 stage1_2_options.safe_extensions = true; |
161 stage1_2_options.safe_extensions = true; |
149 break; |
162 break; |
150 case 'I': |
163 case 'I': |
|
164 /* NOTE: To improve the usability under windows: |
|
165 * We delete last char's path if it ends with "\". |
|
166 * In this way compiler front-end accepts paths with or without |
|
167 * slash terminator. |
|
168 */ |
|
169 path_len = strlen(optarg) - 1; |
|
170 if (optarg[path_len] == '\\') optarg[path_len]= '\0'; |
151 stage1_2_options.includedir = optarg; |
171 stage1_2_options.includedir = optarg; |
152 break; |
172 break; |
153 case 'T': |
173 case 'T': |
|
174 /* NOTE: see note above */ |
|
175 path_len = strlen(optarg) - 1; |
|
176 if (optarg[path_len] == '\\') optarg[path_len]= '\0'; |
154 builddir = optarg; |
177 builddir = optarg; |
155 break; |
178 break; |
156 case ':': /* -I or -T without operand */ |
179 case ':': /* -I or -T without operand */ |
157 fprintf(stderr, "Option -%c requires an operand\n", optopt); |
180 fprintf(stderr, "Option -%c requires an operand\n", optopt); |
158 errflg++; |
181 errflg++; |
196 /* basically loads some symbol tables to speed up look ups later on */ |
219 /* basically loads some symbol tables to speed up look ups later on */ |
197 absyntax_utils_init(tree_root); |
220 absyntax_utils_init(tree_root); |
198 /* moved to bison, although it could perfectly well still be here instead of in bison code. */ |
221 /* moved to bison, although it could perfectly well still be here instead of in bison code. */ |
199 //add_en_eno_param_decl_c::add_to(tree_root); |
222 //add_en_eno_param_decl_c::add_to(tree_root); |
200 |
223 |
201 /* Only very simple (not yet complete) data type checking currently implemented... */ |
224 /* Do semantic verification of code (data type and lvalue checking currently implemented) */ |
202 if (stage3(tree_root) < 0) |
225 if (stage3(tree_root) < 0) |
203 return EXIT_FAILURE; |
226 return EXIT_FAILURE; |
204 |
227 |
205 |
228 |
206 /* 3rd Pass */ |
229 /* 3rd Pass */ |