summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrian Callahan <bcallah@openbsd.org>2019-04-10 04:52:37 +0200
committerJohannes Bucher <johannes.bucher2@student.kit.edu>2019-12-06 15:42:43 +0100
commitb5aab0a87f130db42a056db960c81cd7fd79ce4a (patch)
treea3066544907954ce88dfb9924a4e13b63471bc11
parentc65ed4982fefd5c8e9fb2c24dcd4334246bb8af4 (diff)
Add support for _Pragma.
From nulput on GitHub pull request #16.
-rw-r--r--src/driver/predefs.c2
-rw-r--r--src/parser/preprocessor.c23
-rw-r--r--src/parser/preprocessor.h1
3 files changed, 26 insertions, 0 deletions
diff --git a/src/driver/predefs.c b/src/driver/predefs.c
index d978421..9df0912 100644
--- a/src/driver/predefs.c
+++ b/src/driver/predefs.c
@@ -454,6 +454,8 @@ void add_predefined_macros(void)
/* TODO: __CHAR16_TYPE__, __CHAR32_TYPE__ */
+ define_pragma_macro();
+
/* Add target specific defines */
for (ir_platform_define_t const *define = ir_platform_define_first();
define != NULL; define = ir_platform_define_next(define)) {
diff --git a/src/parser/preprocessor.c b/src/parser/preprocessor.c
index 3a2ec3c..d29fd0d 100644
--- a/src/parser/preprocessor.c
+++ b/src/parser/preprocessor.c
@@ -67,6 +67,7 @@ struct pp_definition_t {
bool is_variadic : 1;
bool standard_define : 1;
bool not_specified : 1;
+ bool is_pragma : 1; /* _Pragma */
};
typedef struct pp_expansion_state_t {
@@ -1124,6 +1125,10 @@ static void start_function_macro_expansion(const macro_call_t *call)
parameter->not_specified = true;
}
}
+ if (current_call.macro->is_pragma) {
+ /* TODO: this is done temporarily for _Pragma */
+ warningf(WARN_UNKNOWN_PRAGMAS, &pp_token.base.pos, "_Pragma is not currently supported");
+ }
pp_expansion_state_t *expansion = begin_expanding(call->macro);
expansion->previous_is_expanding = call->previous_is_expanding;
@@ -2668,6 +2673,24 @@ void add_define_macro(char const *const name, char const *const macro_arg,
def->token_list = obstack_finish(&pp_obstack);
}
+void define_pragma_macro(void)
+{
+ /* _Pragma definition */
+ pp_definition_t *def = add_define_("_Pragma", true);
+
+ symbol_t *const parameter_symbol = symbol_table_insert("directive");
+ pp_definition_t *parameter = OALLOCZ(&pp_obstack, pp_definition_t);
+ parameter->pos = builtin_position;
+ parameter->symbol = parameter_symbol;
+ parameter->is_parameter = true;
+ parameter->is_variadic = false;
+
+ def->has_parameters = true;
+ def->is_pragma = true; /* we catch it later during expansion */
+ def->n_parameters = 1;
+ def->parameters = obstack_finish(&pp_obstack);
+}
+
void parse_define(char const *opt)
{
assert(obstack_object_size(&config_obstack) == 0);
diff --git a/src/parser/preprocessor.h b/src/parser/preprocessor.h
index b065d2a..68a8449 100644
--- a/src/parser/preprocessor.h
+++ b/src/parser/preprocessor.h
@@ -50,6 +50,7 @@ void add_define(char const *name, char const *val, bool standard_define);
void add_define_string(char const *name, char const *val, bool standard_define);
void add_define_macro(char const *name, char const *macro_arg,
char const *val, bool standard_define);
+void define_pragma_macro(void);
void parse_define(char const *string);
void undefine(char const *name);