Split up the printout functions into a file of their own.
[smatch.git] / symbol.h
blob24a8b60aea1cb51f42629a4d29e531a6b44db410
1 #ifndef SEMANTIC_H
2 #define SEMANTIC_H
3 /*
4 * Basic symbol and namespace definitions.
6 * Copyright (C) 2003 Linus Torvalds, all rights reserved.
7 */
9 #include "token.h"
12 * An identifier with semantic meaning is a "symbol".
14 * There's a 1:n relationship: each symbol is always
15 * associated with one identifier, while each identifier
16 * can have one or more semantic meanings due to C scope
17 * rules.
19 * The progression is symbol -> token -> identifier. The
20 * token contains the information on where the symbol was
21 * declared.
23 enum namespace {
24 NS_NONE,
25 NS_PREPROCESSOR,
26 NS_TYPEDEF,
27 NS_STRUCT,
28 NS_ENUM,
29 NS_LABEL,
30 NS_SYMBOL,
33 enum type {
34 SYM_NONE,
35 SYM_TYPE,
36 SYM_PTR,
37 SYM_FN,
38 SYM_ARRAY,
39 SYM_STRUCT,
40 SYM_UNION,
41 SYM_ENUM,
42 SYM_TYPEDEF,
43 SYM_MEMBER,
44 SYM_BITFIELD,
47 struct ctype {
48 unsigned long modifiers;
49 struct symbol *base_type;
52 struct symbol {
53 enum namespace namespace:8;
54 enum type type:8;
55 struct token *token; /* Where this symbol was declared */
56 struct token *ident; /* What identifier this symbol is associated with */
57 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
58 struct symbol **id_list; /* Backpointer to symbol list head */
59 union {
60 struct preprocessor_sym {
61 int busy;
62 struct token *expansion;
63 struct token *arglist;
65 struct ctype_symbol {
66 struct symbol *next; /* Next symbol at this level */
67 unsigned long size;
68 struct ctype ctype;
69 struct symbol_list *arguments;
70 struct statement *stmt;
71 struct symbol_list *symbol_list;
76 /* Modifiers */
77 #define SYM_AUTO 0x0001
78 #define SYM_REGISTER 0x0002
79 #define SYM_STATIC 0x0004
80 #define SYM_EXTERN 0x0008
82 #define SYM_CONST 0x0010
83 #define SYM_VOLATILE 0x0020
84 #define SYM_SIGNED 0x0040
85 #define SYM_UNSIGNED 0x0080
87 #define SYM_CHAR 0x0100
88 #define SYM_SHORT 0x0200
89 #define SYM_LONG 0x0400
90 #define SYM_LONGLONG 0x0800
92 #define SYM_TYPEDEF 0x1000
93 #define SYM_STRUCTOF 0x2000
94 #define SYM_UNIONOF 0x4000
95 #define SYM_ENUMOF 0x8000
97 #define SYM_TYPEOF 0x10000
98 #define SYM_ATTRIBUTE 0x20000
100 /* Basic types */
101 extern struct symbol void_type,
102 int_type,
103 fp_type,
104 vector_type,
105 bad_type;
107 /* Basic identifiers */
108 extern struct ident sizeof_ident,
109 alignof_ident,
110 __alignof_ident,
111 __alignof___ident,
112 if_ident,
113 else_ident,
114 switch_ident,
115 case_ident,
116 default_ident,
117 break_ident,
118 continue_ident,
119 for_ident,
120 while_ident,
121 do_ident,
122 goto_ident,
123 return_ident;
125 extern struct ident __asm___ident,
126 __asm_ident,
127 asm_ident,
128 __volatile___ident,
129 __volatile_ident,
130 volatile_ident,
131 __attribute___ident,
132 __attribute_ident;
134 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
136 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
137 extern void init_symbols(void);
138 extern struct symbol *alloc_symbol(struct token *, int type);
139 extern void show_type(struct symbol *);
140 extern const char *modifier_string(unsigned long mod);
141 extern void show_symbol(struct symbol *);
142 extern void show_type_list(struct symbol *);
143 extern void show_symbol_list(struct symbol_list *, const char *);
144 extern void add_symbol(struct symbol_list **, struct symbol *);
145 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
147 #endif /* SEMANTIC_H */