Chris Lattner | b876183 | 2006-06-24 21:31:03 +0000 | [diff] [blame^] | 1 | //===--- Pragma.cpp - Pragma registration and handling --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the PragmaHandler and PragmaTable interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Lex/Pragma.h" |
| 15 | #include "clang/Lex/Preprocessor.h" |
| 16 | using namespace llvm; |
| 17 | using namespace clang; |
| 18 | |
| 19 | // Out-of-line destructor to provide a home for the class. |
| 20 | PragmaHandler::~PragmaHandler() { |
| 21 | } |
| 22 | |
| 23 | void PragmaNamespace::HandlePragma(Preprocessor &PP, LexerToken &Tok) { |
| 24 | // Read the 'namespace' that the directive is in, e.g. STDC. Do not macro |
| 25 | // expand it, the user can have a STDC #define, that should not affect this. |
| 26 | PP.LexUnexpandedToken(Tok); |
| 27 | |
| 28 | // Get the handler for this token. If there is no handler, ignore the pragma. |
| 29 | PragmaHandler *Handler = FindHandler(Tok.getIdentifierInfo(), false); |
| 30 | if (Handler == 0) return; |
| 31 | |
| 32 | // Otherwise, pass it down. |
| 33 | Handler->HandlePragma(PP, Tok); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | |
| 38 | #if 0 |
| 39 | /* Contains a registered pragma or pragma namespace. */ |
| 40 | typedef void (*pragma_cb) (cpp_reader *); |
| 41 | struct pragma_entry |
| 42 | { |
| 43 | struct pragma_entry *next; |
| 44 | const cpp_hashnode *pragma; /* Name and length. */ |
| 45 | bool is_nspace; |
| 46 | bool is_internal; |
| 47 | bool is_deferred; |
| 48 | bool allow_expansion; |
| 49 | union { |
| 50 | pragma_cb handler; |
| 51 | struct pragma_entry *space; |
| 52 | unsigned int ident; |
| 53 | } u; |
| 54 | }; |
| 55 | |
| 56 | |
| 57 | |
| 58 | /* Register a pragma NAME in namespace SPACE. If SPACE is null, it |
| 59 | goes in the global namespace. HANDLER is the handler it will call, |
| 60 | which must be non-NULL. If ALLOW_EXPANSION is set, allow macro |
| 61 | expansion while parsing pragma NAME. This function is exported |
| 62 | from libcpp. */ |
| 63 | void |
| 64 | cpp_register_pragma (cpp_reader *pfile, const char *space, const char *name, |
| 65 | pragma_cb handler, bool allow_expansion) |
| 66 | { |
| 67 | struct pragma_entry *entry; |
| 68 | |
| 69 | if (!handler) |
| 70 | { |
| 71 | cpp_error (pfile, CPP_DL_ICE, "registering pragma with NULL handler"); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | entry = register_pragma_1 (pfile, space, name, false); |
| 76 | if (entry) |
| 77 | { |
| 78 | entry->allow_expansion = allow_expansion; |
| 79 | entry->u.handler = handler; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /* Similarly, but create mark the pragma for deferred processing. |
| 84 | When found, a CPP_PRAGMA token will be insertted into the stream |
| 85 | with IDENT in the token->u.pragma slot. */ |
| 86 | void |
| 87 | cpp_register_deferred_pragma (cpp_reader *pfile, const char *space, |
| 88 | const char *name, unsigned int ident, |
| 89 | bool allow_expansion, bool allow_name_expansion) |
| 90 | { |
| 91 | struct pragma_entry *entry; |
| 92 | |
| 93 | entry = register_pragma_1 (pfile, space, name, allow_name_expansion); |
| 94 | if (entry) |
| 95 | { |
| 96 | entry->is_deferred = true; |
| 97 | entry->allow_expansion = allow_expansion; |
| 98 | entry->u.ident = ident; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | |
| 103 | /* Register the pragmas the preprocessor itself handles. */ |
| 104 | void |
| 105 | _cpp_init_internal_pragmas (cpp_reader *pfile) |
| 106 | { |
| 107 | /* Pragmas in the global namespace. */ |
| 108 | register_pragma_internal (pfile, 0, "once", do_pragma_once); |
| 109 | |
| 110 | /* New GCC-specific pragmas should be put in the GCC namespace. */ |
| 111 | register_pragma_internal (pfile, "GCC", "poison", do_pragma_poison); |
| 112 | register_pragma_internal (pfile, "GCC", "system_header", |
| 113 | do_pragma_system_header); |
| 114 | register_pragma_internal (pfile, "GCC", "dependency", do_pragma_dependency); |
| 115 | } |
| 116 | #endif |