projects
/
cparser
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
improvements for handling of function parameters
[cparser]
/
main.c
diff --git
a/main.c
b/main.c
index
799f364
..
58e0601
100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-5,8
+5,9
@@
#include <errno.h>
#include <string.h>
#include <errno.h>
#include <string.h>
-#include "lexer
_t
.h"
+#include "lexer.h"
#include "token_t.h"
#include "token_t.h"
+#include "type_hash.h"
#include "parser.h"
#if 0
#include "parser.h"
#if 0
@@
-36,10
+37,26
@@
void get_output_name(char *buf, size_t buflen, const char *inputname,
#endif
static
#endif
static
-
void compile
(const char *fname)
+
translation_unit_t *do_parsing
(const char *fname)
{
{
- token_t token;
+ FILE *in = fopen(fname, "r");
+ if(in == NULL) {
+ fprintf(stderr, "Couldn't open '%s': %s\n", fname, strerror(errno));
+ exit(1);
+ }
+
+ lexer_open_stream(in, fname);
+
+ translation_unit_t *unit = parse();
+
+ fclose(in);
+ return unit;
+}
+
+static
+void lextest(const char *fname)
+{
FILE *in = fopen(fname, "r");
if(in == NULL) {
fprintf(stderr, "Couldn't open '%s': %s\n", fname, strerror(errno));
FILE *in = fopen(fname, "r");
if(in == NULL) {
fprintf(stderr, "Couldn't open '%s': %s\n", fname, strerror(errno));
@@
-49,26
+66,47
@@
void compile(const char *fname)
lexer_open_stream(in, fname);
do {
lexer_open_stream(in, fname);
do {
- lexer_next_
token(&token
);
- print_token(stdout, &token);
+ lexer_next_
preprocessing_token(
);
+ print_token(stdout, &
lexer_
token);
puts("");
puts("");
- } while(token.type != T_EOF);
+ } while(
lexer_
token.type != T_EOF);
fclose(in);
}
fclose(in);
}
+void write_fluffy_decls(translation_unit_t *unit);
+
int main(int argc, char **argv)
{
init_symbol_table();
init_tokens();
init_lexer();
int main(int argc, char **argv)
{
init_symbol_table();
init_tokens();
init_lexer();
+ init_types();
+ init_typehash();
+ init_ast();
init_parser();
init_parser();
+ if(argc > 2 && strcmp(argv[1], "--lextest") == 0) {
+ lextest(argv[2]);
+ return 0;
+ }
+
+ if(argc > 2 && strcmp(argv[1], "--print-ast") == 0) {
+ translation_unit_t *unit = do_parsing(argv[2]);
+ ast_set_output(stdout);
+ print_ast(unit);
+ return 0;
+ }
+
for(int i = 1; i < argc; ++i) {
for(int i = 1; i < argc; ++i) {
- compile(argv[i]);
+ translation_unit_t *unit = do_parsing(argv[i]);
+ write_fluffy_decls(unit);
}
exit_parser();
}
exit_parser();
+ exit_ast();
+ exit_typehash();
+ exit_types();
exit_lexer();
exit_tokens();
exit_symbol_table();
exit_lexer();
exit_tokens();
exit_symbol_table();