xref: /Universal-ctags/peg/varlink_post.h (revision 697bbc6840a544c22083a0f9ae19869f1bbade8c)
1 /*
2  *   Copyright (c) 2019 Masatake YAMATO
3  *   Copyright (c) 2019 Red Hat, Inc.
4  *
5  *   This source code is released for free distribution under the terms of the
6  *   GNU General Public License version 2 or (at your option) any later version.
7  *
8  *   This module contains functions to generate tags for Varlink.
9  */
10 
11 /*
12 *   INCLUDE FILES
13 */
14 #include "options.h"
15 #include "parse.h"
16 #include "routines.h"
17 
18 /*
19 * FUNCTION DEFINITIONS
20 */
pushKindContextual(struct parserCtx * auxil)21 static void pushKindContextual (struct parserCtx *auxil)
22 {
23 	int k0 = basePeekKind(BASE(auxil));
24 	int k = KIND_GHOST_INDEX;
25 
26 	switch (k0)
27 	{
28 	case K_METHOD:
29 		if (auxil->mparam_state == METHOD_PARAM_INPUT)
30 			k = K_IPARAM;
31 		else
32 			k = K_OPARAM;
33 		break;
34 	case K_STRUCT:
35 		k = K_FIELD;
36 		break;
37 	case K_ENUM:
38 		k = K_ENUMERATION;
39 		break;
40 	case K_ERROR:
41 		k = K_EDESC;
42 		break;
43 	default:
44 		k = k0;
45 		break;
46 	}
47 
48 	basePushKind (BASE(auxil), k);
49 }
50 
setMethodParamState(struct parserCtx * auxil,methodParamState s)51 static void setMethodParamState (struct parserCtx *auxil, methodParamState s)
52 {
53 	auxil->mparam_state = s;
54 }
55 
makeVarlinkTag(struct parserCtx * auxil,const char * name,long offset)56 static int makeVarlinkTag (struct parserCtx *auxil, const char *name, long offset)
57 {
58 	tagEntryInfo e;
59 	int k = PEEK_KIND (auxil);
60 	initTagEntry(&e, name, k);
61 	e.lineNumber = getInputLineNumberForFileOffset (offset);
62 	e.filePosition = getInputFilePositionForLine (e.lineNumber);
63 	e.extensionFields.scopeIndex = BASE_SCOPE (auxil);
64 	return makeTagEntry (&e);
65 }
66 
ctxInit(struct parserCtx * auxil)67 static void ctxInit (struct parserCtx *auxil)
68 {
69 	BASE_INIT(auxil, K_INTERFACE);
70 }
71 
ctxFini(struct parserCtx * auxil)72 static void ctxFini (struct parserCtx *auxil)
73 {
74 	BASE_FINI(auxil);
75 }
76 
findVarlinkTags(void)77 static void findVarlinkTags (void)
78 {
79 	struct parserCtx auxil;
80 
81 	ctxInit (&auxil);
82 	pvarlink_context_t *pctx = pvarlink_create(&auxil);
83 
84 	while (pvarlink_parse(pctx, NULL) && (!BASE_ERROR(&auxil)) );
85 
86 	pvarlink_destroy(pctx);
87 	ctxFini (&auxil);
88 }
89 
VarlinkParser(void)90 extern parserDefinition* VarlinkParser (void)
91 {
92 	static const char *const extensions [] = { "varlink", NULL };
93 	parserDefinition* def = parserNew ("Varlink");
94 	def->kindTable  = VarlinkKinds;
95 	def->kindCount  = ARRAY_SIZE (VarlinkKinds);
96 	def->extensions = extensions;
97 	def->parser     = findVarlinkTags;
98 	def->useCork    = true;
99 	def->enabled    = true;
100 	def->defaultScopeSeparator = ".";
101 	return def;
102 }
103