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
81d4760
..
58e0601
100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-5,8
+5,10
@@
#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
static
#if 0
static
@@
-35,38
+37,77
@@
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)
{
{
- lexer_t lexer;
- 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));
exit(1);
}
FILE *in = fopen(fname, "r");
if(in == NULL) {
fprintf(stderr, "Couldn't open '%s': %s\n", fname, strerror(errno));
exit(1);
}
- lexer_
init(&lexer,
in, fname);
+ lexer_
open_stream(
in, fname);
do {
do {
- lexer_next_
token(&lexer, &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);
- lexer_destroy(&lexer);
fclose(in);
}
fclose(in);
}
+void write_fluffy_decls(translation_unit_t *unit);
+
int main(int argc, char **argv)
{
init_symbol_table();
init_tokens();
int main(int argc, char **argv)
{
init_symbol_table();
init_tokens();
+ init_lexer();
+ init_types();
+ init_typehash();
+ init_ast();
+ 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_ast();
+ exit_typehash();
+ exit_types();
+ exit_lexer();
exit_tokens();
exit_symbol_table();
return 0;
exit_tokens();
exit_symbol_table();
return 0;