[PATCH] evaluate_sign() typo
[smatch.git] / test-parsing.c
blob307997cfb9a7fb4b4a5bed55f9a8eacc10210646
1 /*
2 * Example trivial client program that uses the sparse library
3 * to tokenize, pre-process and parse a C file, and prints out
4 * the results.
6 * Copyright (C) 2003 Transmeta Corp.
7 * 2003 Linus Torvalds
9 * Licensed under the Open Software License version 1.1
11 #include <stdarg.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include <unistd.h>
17 #include <fcntl.h>
19 #include "lib.h"
20 #include "token.h"
21 #include "parse.h"
22 #include "symbol.h"
23 #include "expression.h"
25 static void clean_up_symbol(struct symbol *sym, void *_parent, int flags)
27 evaluate_symbol(sym);
28 expand_symbol(sym);
31 int main(int argc, char **argv)
33 int fd;
34 char *filename = NULL, **args;
35 struct token *token;
37 // Initialize symbol stream first, so that we can add defines etc
38 init_symbols();
40 create_builtin_stream();
42 args = argv;
43 for (;;) {
44 char *arg = *++args;
45 if (!arg)
46 break;
47 if (arg[0] == '-') {
48 args = handle_switch(arg + 1, args);
49 continue;
51 filename = arg;
54 // Initialize type system
55 init_ctype();
57 fd = open(filename, O_RDONLY);
58 if (fd < 0)
59 die("No such file: %s", argv[1]);
61 // Tokenize the input stream
62 token = tokenize(filename, fd, NULL, includepath);
63 close(fd);
65 // Prepend the initial built-in stream
66 token = tokenize_buffer(pre_buffer, pre_buffer_size, token);
68 // Pre-process the stream
69 token = preprocess(token);
71 // Parse the resulting C code
72 translation_unit(token, &used_list);
74 // Do type evaluation and simplification
75 symbol_iterate(used_list, clean_up_symbol, NULL);
77 #if 1
78 // Show the end result.
79 show_symbol_list(used_list, "\n\n");
80 printf("\n\n");
81 #endif
83 #if 0
84 // And show the allocation statistics
85 show_ident_alloc();
86 show_token_alloc();
87 show_symbol_alloc();
88 show_expression_alloc();
89 show_statement_alloc();
90 show_string_alloc();
91 show_bytes_alloc();
92 #endif
93 return 0;