]> pd.if.org Git - lice/blob - opt.c
autocommit for files dated 2014-11-17 20:15:20
[lice] / opt.c
1 #include "opt.h"
2
3 static const opt_extension_t opt_extension_matrix[] = {
4     /*
5      * same as GNUC but no dollar identifiers, they don't make much sense
6      * and in C11 mode, opposed to GNUC which is C99
7      */
8     [STANDARD_LICEC] = EXTENSION_TYPEOF          | EXTENSION_OMITOPCOND      |
9                        EXTENSION_STATEMENTEXPRS  | EXTENSION_NOMEMBERSTRUCT  |
10                        EXTENSION_CASERANGES      | EXTENSION_ESCCHAR         |
11                        EXTENSION_INCOMPLETEENUM  | EXTENSION_BINARYCONSTANTS |
12                        EXTENSION_ARITHMETICVOID  | EXTENSION_LABELASVALUES   |
13                        EXTENSION_ZEROARRAYS      | EXTENSION_ZEROARRAYS      |
14                        EXTENSION_NONCONSTINIT    | EXTENSION_NONSTANDARD,
15
16     /*
17      * standard GNUC format, TODO: -std=gnuc90, which is the same as this
18      * but C90, instead of C90
19      */
20     [STANDARD_GNUC]  = EXTENSION_TYPEOF          | EXTENSION_OMITOPCOND      |
21                        EXTENSION_STATEMENTEXPRS  | EXTENSION_NOMEMBERSTRUCT  |
22                        EXTENSION_CASERANGES      | EXTENSION_ESCCHAR         |
23                        EXTENSION_INCOMPLETEENUM  | EXTENSION_BINARYCONSTANTS |
24                        EXTENSION_ARITHMETICVOID  | EXTENSION_LABELASVALUES   |
25                        EXTENSION_ZEROARRAYS      | EXTENSION_ZEROARRAYS      |
26                        EXTENSION_NONCONSTINIT    | EXTENSION_DOLLAR          |
27                        EXTENSION_NONSTANDARD,
28
29     [STANDARD_C90]   = 0,
30     [STANDARD_C99]   = 0,
31     [STANDARD_C11]   = 0
32 };
33
34 static opt_std_t       standard   = STANDARD_LICEC;
35 static opt_extension_t extensions = ~0;
36
37 bool opt_std_test(opt_std_t std) {
38     return (standard == std);
39 }
40
41 bool opt_extension_test(opt_extension_t ext) {
42     return (extensions & ext);
43 }
44
45 void opt_std_set(opt_std_t std) {
46     standard   = std;
47     extensions = opt_extension_matrix[std];
48 }
49
50 void opt_extension_set(opt_extension_t ext) {
51     if (opt_extension_matrix[standard] & ext)
52         extensions &= ext;
53 }