-- init_compile_env
[silentbob2.git] / sblib / wit.cxx
blobf33b752e1bd4ae230c012d5899b41af0862d1f1b
1 /*
2 * (c) Oleg Puchinin 2006.
3 * graycardinalster@gmail.com
5 */
7 #include <head.h>
8 #include <wit.h>
10 int what_is_this (char * d_op, char ch)
12 bool b_local_ftest;
13 int d_words_count;
14 char d_last_ch;
15 char * S;
16 int Ret = 0;
18 if (*d_op == '#' || ch == '\n') {
19 if (def_test (d_op))
20 return OT::Define;
21 return OT::Macro;
24 d_words_count = words_count (d_op);
26 if (words_count <= 0)
27 return OT::Other;
29 if (d_words_count == 1) {
30 if (ww_call_cmp (d_op, (char *) "if", 2) ||
31 ww_call_cmp (d_op, (char *) "else", 4) ||
32 ww_call_cmp (d_op, (char *) "do", 2) ||
33 ww_call_cmp (d_op, (char *) "while", 5) ||
34 ww_call_cmp (d_op, (char *) "switch", 6) ||
35 ww_case_cmp (d_op, (char *) "case", 4))
36 return OT::Operator;
38 if (ww_after_word (d_op) == '(')
39 return OT::Call;
41 return OT::Other; // Macro or operations (e.g. "+-=*/%^" etc...)
44 if (! strncmp (d_op, "else if ", 8))
45 return OT::Operator;
46 if (! strncmp (d_op, "class ", 6) && ch == ';') // class definition
47 return OT::Other;
49 d_last_ch = last_ch (d_op);
50 if (d_last_ch == '=')
51 return OT::Variable;
53 b_local_ftest = local_ftest (d_op);
54 if ((ch == '{' && d_last_ch == ')')) {
55 if (b_local_ftest) // Paranoid.
56 return OT::Function;
59 if (! strncmp (d_op, "extern ", 7))
60 return OT::Extern;
62 if (ch == '{') {
63 Ret = 0;
64 if (! strncmp (d_op, "typedef ", 8)) {
65 Ret |= OT::Typedef;
66 d_op += 8;
69 if (! strncmp (d_op, "static ", 7))
70 d_op += 7;
72 if (! strncmp (d_op, "const ", 6)) // "static const struct"
73 d_op += 6;
75 if (! strncmp (d_op, "union ", 6))
76 return Ret | OT::Other;
78 if (! strncmp (d_op, "enum ", 5))
79 return Ret | OT::Other;
81 if (! strncmp (d_op, "struct ", 7))
82 return Ret | OT::Struct;
84 if (! strncmp (d_op, "class ", 6))
85 return OT::Class;
87 if (! strncmp (d_op, "namespace ", 10))
88 return OT::Namespace;
90 if ((words_count (d_op) > 1) && !b_local_ftest)
91 return OT::Variable;
93 if (Ret)
94 return Ret;
95 return OT::Other;
98 if (ch == ';') {
99 if (!strncmp (d_op, "typedef ", 8))
100 return OT::Typedef;
102 if (b_local_ftest) {
103 S = strchr (d_op, '(');
104 if (! S)
105 return OT::Other;
107 S++;
108 if (words_count (S) <= 1) {
109 S = strchr_r (S, ')', 0);
110 S++;
111 if (words_count (S) > 1)
112 return OT::Other; // declaration... or not ?
114 } else {
115 if (d_words_count <= 1)
116 return OT::Other;
118 if (!strncmp (d_op, "struct ", 7) && d_words_count == 2)
119 return OT::Other;
121 if (!strncmp (d_op, "return ", 7))
122 return OT::Other;
124 if (!strncmp (d_op, "delete ", 7))
125 return OT::Other;
127 return OT::Variable;
129 // Function defenition, callback defenition... it's all ?
132 return OT::Other;