1 /* 2 * Copyright (c) 2021 Masatake YAMATO 3 * 4 * This source code is released for free distribution under the terms of the 5 * GNU General Public License version 2 or (at your option) any later version. 6 * 7 * This module contains macros, data decls and prototypes to generate tags for Thrift IDL. 8 * Reference: https://thrift.apache.org/docs/idl 9 */ 10 11 /* 12 * INCLUDE FILES 13 */ 14 #include "kind.h" 15 #include "field.h" 16 #include "peg_common.h" 17 18 #include "parsers/cxx/cxx_tag.h" 19 20 /* 21 * MACROS 22 */ 23 24 /* 25 * DATA DECLARATIONS 26 */ 27 typedef enum { 28 K_STRUCT, 29 K_EXCEPTION, 30 K_UNION, 31 K_NAMESPACE, 32 K_ENUMERATOR, 33 K_ENUM, 34 K_MEMBER, 35 K_CONST, 36 K_TYPEDEF, 37 K_SERVICE, 38 K_FUNCTION, 39 K_PARAMETER, 40 K_THROWSPARAM, 41 K_THRIFTFILE, 42 COUNT_KINDS 43 } thriftKind; 44 45 typedef enum { 46 THRIFT_THRIFT_FILE_INCLUDED, 47 } thriftThriftFileRole; 48 49 static roleDefinition ThriftThriftFileRoles [] = { 50 { true, "included", "included file" }, 51 }; 52 53 static kindDefinition ThriftKinds [COUNT_KINDS] = { 54 { true, 's', "struct", "structs" }, 55 { true, 'x', "exception", "exceptions" }, 56 { true, 'u', "union", "unions" }, 57 { true, 'n', "namespace", "namespaces" }, 58 { true, 'e', "enumerator", "enumerators (values inside an enumeration)" }, 59 { true, 'g', "enum", "enumeration names" }, 60 { true, 'm', "member", "members" }, 61 { true, 'C', "const", "constants" }, 62 { true, 't', "typedef", "typedefs" }, 63 { true, 'v', "service", "services" }, 64 { true, 'f', "function", "functions" }, 65 { false, 'z', "parameter", "parameters" }, 66 { false, 'Z', "throwsparam", "parameters in throws list" }, 67 { true, 'T', "thriftFile", "thrift files", 68 .referenceOnly = true, ATTACH_ROLES(ThriftThriftFileRoles) }, 69 }; 70 71 typedef enum { 72 F_THROWS, 73 F_TARGET, 74 COUNT_FIELDS 75 } thriftField; 76 77 static fieldDefinition ThriftFields[COUNT_FIELDS] = { 78 { .name = "throws", 79 .description = "throws list of function", 80 .enabled = true }, 81 { .name = "target", 82 .description = "the target language specified at \"namespace\"", 83 .enabled = true }, 84 }; 85 86 struct parserCtx { 87 struct parserBaseCtx base; 88 }; 89 90 /* 91 * FUNCTION PROTOTYPES 92 */ 93 #define USE_KIND_STACK KIND_GHOST_INDEX 94 static int makeThriftTagFull (struct parserCtx *auxil, const char *name, long offset, int kind, int role, bool pushScope); 95 static int makeThriftTag (struct parserCtx *auxil, const char *name, long offset, int kind, bool pushScope); 96 static vString* unliteral(const char *literal); 97