extra, db: record a dummy output for every function call
[smatch.git] / token.h
blob1a9c75cd949df49006efbe1f57dc19b5e29acbb3
1 #ifndef TOKEN_H
2 #define TOKEN_H
3 /*
4 * Basic tokenization structures. NOTE! Those tokens had better
5 * be pretty small, since we're going to keep them all in memory
6 * indefinitely.
8 * Copyright (C) 2003 Transmeta Corp.
9 * 2003 Linus Torvalds
11 * Licensed under the Open Software License version 1.1
14 #include <sys/types.h>
15 #include "lib.h"
18 * This describes the pure lexical elements (tokens), with
19 * no semantic meaning. In other words, an identifier doesn't
20 * have a type or meaning, it is only a specific string in
21 * the input stream.
23 * Semantic meaning is handled elsewhere.
26 enum constantfile {
27 CONSTANT_FILE_MAYBE, // To be determined, not inside any #ifs in this file
28 CONSTANT_FILE_IFNDEF, // To be determined, currently inside #ifndef
29 CONSTANT_FILE_NOPE, // No
30 CONSTANT_FILE_YES // Yes
33 extern const char *includepath[];
35 struct stream {
36 int fd;
37 const char *name;
38 const char *path; // input-file path - see set_stream_include_path()
39 const char **next_path;
41 /* Use these to check for "already parsed" */
42 enum constantfile constant;
43 int dirty;
44 struct ident *protect;
45 struct token *ifndef;
46 struct token *top_if;
49 extern int input_stream_nr;
50 extern struct stream *input_streams;
51 extern unsigned int tabstop;
52 extern int no_lineno;
54 struct ident {
55 struct ident *next; /* Hash chain of identifiers */
56 struct symbol *symbols; /* Pointer to semantic meaning list */
57 unsigned char len; /* Length of identifier name */
58 unsigned char tainted:1,
59 reserved:1,
60 keyword:1;
61 char name[]; /* Actual identifier */
64 enum token_type {
65 TOKEN_EOF,
66 TOKEN_ERROR,
67 TOKEN_IDENT,
68 TOKEN_ZERO_IDENT,
69 TOKEN_NUMBER,
70 TOKEN_CHAR,
71 TOKEN_WIDE_CHAR,
72 TOKEN_STRING,
73 TOKEN_WIDE_STRING,
74 TOKEN_SPECIAL,
75 TOKEN_STREAMBEGIN,
76 TOKEN_STREAMEND,
77 TOKEN_MACRO_ARGUMENT,
78 TOKEN_STR_ARGUMENT,
79 TOKEN_QUOTED_ARGUMENT,
80 TOKEN_CONCAT,
81 TOKEN_GNU_KLUDGE,
82 TOKEN_UNTAINT,
83 TOKEN_ARG_COUNT,
84 TOKEN_IF,
85 TOKEN_SKIP_GROUPS,
86 TOKEN_ELSE,
89 /* Combination tokens */
90 #define COMBINATION_STRINGS { \
91 "+=", "++", \
92 "-=", "--", "->", \
93 "*=", \
94 "/=", \
95 "%=", \
96 "<=", ">=", \
97 "==", "!=", \
98 "&&", "&=", \
99 "||", "|=", \
100 "^=", "##", \
101 "<<", ">>", "..", \
102 "<<=", ">>=", "...", \
103 "", \
104 "<", ">", "<=", ">=" \
107 extern unsigned char combinations[][4];
109 enum special_token {
110 SPECIAL_BASE = 256,
111 SPECIAL_ADD_ASSIGN = SPECIAL_BASE,
112 SPECIAL_INCREMENT,
113 SPECIAL_SUB_ASSIGN,
114 SPECIAL_DECREMENT,
115 SPECIAL_DEREFERENCE,
116 SPECIAL_MUL_ASSIGN,
117 SPECIAL_DIV_ASSIGN,
118 SPECIAL_MOD_ASSIGN,
119 SPECIAL_LTE,
120 SPECIAL_GTE,
121 SPECIAL_EQUAL,
122 SPECIAL_NOTEQUAL,
123 SPECIAL_LOGICAL_AND,
124 SPECIAL_AND_ASSIGN,
125 SPECIAL_LOGICAL_OR,
126 SPECIAL_OR_ASSIGN,
127 SPECIAL_XOR_ASSIGN,
128 SPECIAL_HASHHASH,
129 SPECIAL_LEFTSHIFT,
130 SPECIAL_RIGHTSHIFT,
131 SPECIAL_DOTDOT,
132 SPECIAL_SHL_ASSIGN,
133 SPECIAL_SHR_ASSIGN,
134 SPECIAL_ELLIPSIS,
135 SPECIAL_ARG_SEPARATOR,
136 SPECIAL_UNSIGNED_LT,
137 SPECIAL_UNSIGNED_GT,
138 SPECIAL_UNSIGNED_LTE,
139 SPECIAL_UNSIGNED_GTE,
142 struct string {
143 unsigned int length;
144 char data[];
147 /* will fit into 32 bits */
148 struct argcount {
149 unsigned normal:10;
150 unsigned quoted:10;
151 unsigned str:10;
152 unsigned vararg:1;
156 * This is a very common data structure, it should be kept
157 * as small as humanly possible. Big (rare) types go as
158 * pointers.
160 struct token {
161 struct position pos;
162 struct token *next;
163 union {
164 const char *number;
165 struct ident *ident;
166 unsigned int special;
167 struct string *string;
168 int character;
169 int argnum;
170 struct argcount count;
174 #define MAX_STRING 4095
176 static inline struct token *containing_token(struct token **p)
178 void *addr = (char *)p - ((char *)&((struct token *)0)->next - (char *)0);
179 return addr;
182 #define token_type(x) ((x)->pos.type)
185 * Last token in the stream - points to itself.
186 * This allows us to not test for NULL pointers
187 * when following the token->next chain..
189 extern struct token eof_token_entry;
190 #define eof_token(x) ((x) == &eof_token_entry)
192 extern int init_stream(const char *, int fd, const char **next_path);
193 extern const char *stream_name(int stream);
194 extern struct ident *hash_ident(struct ident *);
195 extern struct ident *built_in_ident(const char *);
196 extern struct token *built_in_token(int, const char *);
197 extern const char *show_special(int);
198 extern const char *show_ident(const struct ident *);
199 extern const char *show_string(const struct string *string);
200 extern const char *show_token(const struct token *);
201 extern struct token * tokenize(const char *, int, struct token *, const char **next_path);
202 extern struct token * tokenize_buffer(void *, unsigned long, struct token **);
204 extern void show_identifier_stats(void);
205 extern struct token *preprocess(struct token *);
207 extern void store_macro_pos(struct token *);
208 extern char *get_macro_name(struct position *);
210 static inline int match_op(struct token *token, int op)
212 return token->pos.type == TOKEN_SPECIAL && token->special == op;
215 static inline int match_ident(struct token *token, struct ident *id)
217 return token->pos.type == TOKEN_IDENT && token->ident == id;
220 #endif