1 /** 2 * @file pcf_flags.h 3 * 4 * @author Guy Maurel 5 * @license GPL v2+ 6 */ 7 8 #ifndef PCF_FLAGS_STR_INCLUDED 9 #define PCF_FLAGS_STR_INCLUDED 10 11 #include "enum_flags.h" 12 #include "logger.h" 13 14 #include <cstddef> // do get the definition of size_t 15 16 // and the ever-so-important array size macro 17 #ifndef ARRAY_SIZE 18 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 19 #endif 20 21 using namespace std; 22 23 24 constexpr auto pcf_bit(size_t b) -> decltype(0ULL) 25 { 26 return(1ULL << b); 27 } 28 29 enum pcf_flag_e : decltype ( 0ULL ) 30 { 31 // Copy flags are in the lower 17 bits 32 PCF_NONE = 0ULL, 33 PCF_COPY_FLAGS = 0x0001ffffULL, 34 PCF_IN_PREPROC = pcf_bit(0), //! in a preprocessor 35 PCF_IN_STRUCT = pcf_bit(1), //! in a struct 36 PCF_IN_ENUM = pcf_bit(2), //! in enum 37 PCF_IN_FCN_DEF = pcf_bit(3), //! inside function def parens 38 PCF_IN_FCN_CALL = pcf_bit(4), //! inside function call parens 39 PCF_IN_SPAREN = pcf_bit(5), //! inside for/if/while/switch parens 40 PCF_IN_TEMPLATE = pcf_bit(6), 41 PCF_IN_TYPEDEF = pcf_bit(7), 42 PCF_IN_CONST_ARGS = pcf_bit(8), 43 PCF_IN_ARRAY_ASSIGN = pcf_bit(9), 44 PCF_IN_CLASS = pcf_bit(10), 45 PCF_IN_CLASS_BASE = pcf_bit(11), 46 PCF_IN_NAMESPACE = pcf_bit(12), 47 PCF_IN_FOR = pcf_bit(13), 48 PCF_IN_OC_MSG = pcf_bit(14), 49 PCF_IN_WHERE_SPEC = pcf_bit(15), /* inside C# 'where' constraint clause on class or function def */ 50 PCF_IN_DECLTYPE = pcf_bit(16), 51 52 // Non-Copy flags are in the upper 47 bits 53 PCF_FORCE_SPACE = pcf_bit(17), //! must have a space after this token 54 PCF_STMT_START = pcf_bit(18), //! marks the start of a statement 55 PCF_EXPR_START = pcf_bit(19), 56 PCF_DONT_INDENT = pcf_bit(20), //! already aligned! 57 PCF_ALIGN_START = pcf_bit(21), 58 PCF_WAS_ALIGNED = pcf_bit(22), 59 PCF_VAR_TYPE = pcf_bit(23), //! part of a variable def type 60 PCF_VAR_DEF = pcf_bit(24), //! variable name in a variable def 61 PCF_VAR_1ST = pcf_bit(25), //! 1st variable def in a statement 62 PCF_VAR_1ST_DEF = (PCF_VAR_DEF | PCF_VAR_1ST), 63 PCF_VAR_INLINE = pcf_bit(26), //! type was an inline struct/enum/union 64 PCF_RIGHT_COMMENT = pcf_bit(27), 65 PCF_OLD_FCN_PARAMS = pcf_bit(28), 66 PCF_LVALUE = pcf_bit(29), //! left of assignment 67 PCF_ONE_LINER = pcf_bit(30), 68 PCF_ONE_CLASS = (PCF_ONE_LINER | PCF_IN_CLASS), 69 PCF_EMPTY_BODY = pcf_bit(31), 70 PCF_ANCHOR = pcf_bit(32), //! aligning anchor 71 PCF_PUNCTUATOR = pcf_bit(33), 72 PCF_INSERTED = pcf_bit(34), //! chunk was inserted from another file 73 PCF_LONG_BLOCK = pcf_bit(35), //! the block is 'long' by some measure 74 PCF_OC_BOXED = pcf_bit(36), //! inside OC boxed expression 75 PCF_KEEP_BRACE = pcf_bit(37), //! do not remove brace 76 PCF_OC_RTYPE = pcf_bit(38), //! inside OC return type 77 PCF_OC_ATYPE = pcf_bit(39), //! inside OC arg type 78 PCF_WF_ENDIF = pcf_bit(40), //! #endif for whole file ifdef 79 PCF_IN_QT_MACRO = pcf_bit(41), //! in a QT-macro, i.e. SIGNAL, SLOT 80 PCF_IN_FCN_CTOR = pcf_bit(42), //! inside function constructor 81 PCF_IN_TRY_BLOCK = pcf_bit(43), //! inside Function-try-block 82 PCF_INCOMPLETE = pcf_bit(44), //! class/struct forward declaration 83 PCF_IN_LAMBDA = pcf_bit(45), //! inside a lambda expression 84 PCF_WF_IF = pcf_bit(46), //! #if for a whole file ifdef 85 PCF_NOT_POSSIBLE = pcf_bit(47), //! it is not possible to make an one_liner 86 //! because the line would be too long 87 }; 88 89 UNC_DECLARE_FLAGS(pcf_flags_t, pcf_flag_e); 90 UNC_DECLARE_OPERATORS_FOR_FLAGS(pcf_flags_t); 91 92 std::string pcf_flags_str(pcf_flags_t flags); 93 94 95 void log_pcf_flags(log_sev_t sev, pcf_flags_t flags); 96 97 98 #endif /* PCF_FLAGS_STR_INCLUDED */ 99