1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/*
* Copyright (c) 2019 Masatake YAMATO
* Copyright (c) 2019 Red Hat, Inc.
*
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
* This module contains functions to generate tags for Varlink.
*/
/*
* INCLUDE FILES
*/
#include "debug.h"
#include "options.h"
#include "parse.h"
#include "routines.h"
/*
* FUNCTION DEFINITIONS
*/
static void pushKind (struct parserCtx *auxil, int kind)
{
intArrayAdd (auxil->kind_stack, kind);
}
static void popKind (struct parserCtx *auxil, bool popScopeToo)
{
intArrayRemoveLast (auxil->kind_stack);
if (popScopeToo)
{
tagEntryInfo *e = getEntryInCorkQueue (auxil->scope_cork_index);
if (e)
auxil->scope_cork_index = e->extensionFields.scopeIndex;
}
}
static void pushKindContextual (struct parserCtx *auxil)
{
int k0 = intArrayLast (auxil->kind_stack);
int k = KIND_GHOST_INDEX;
switch (k0)
{
case K_METHOD:
if (auxil->mparam_state == METHOD_PARAM_INPUT)
k = K_IPARAM;
else
k = K_OPARAM;
break;
case K_STRUCT:
k = K_FIELD;
break;
case K_ENUM:
k = K_ENUMERATION;
break;
case K_ERROR:
k = K_EDESC;
break;
default:
k = k0;
break;
}
pushKind (auxil, k);
}
static int peekKind (struct parserCtx *auxil)
{
return intArrayLast (auxil->kind_stack);
}
static void setMethodParamState (struct parserCtx *auxil, methodParamState s)
{
auxil->mparam_state = s;
}
static void reportError (struct parserCtx *auxil)
{
auxil->found_syntax_error = true;
verbose ("%s: syntax error in \"%s\"\n",
getLanguageName (getInputLanguage ()),
getInputFileName());
}
static int makeVarlinkTag (struct parserCtx *auxil, const char *name, long offset)
{
tagEntryInfo e;
int k = peekKind (auxil);
initTagEntry(&e, name, k);
e.lineNumber = getInputLineNumberForFileOffset (offset);
e.filePosition = getInputFilePositionForLine (e.lineNumber);
e.extensionFields.scopeIndex = auxil->scope_cork_index;
return makeTagEntry (&e);
}
static void ctxInit (struct parserCtx *auxil)
{
auxil->kind_stack = intArrayNew ();
pushKind (auxil, K_INTERFACE);
auxil->scope_cork_index = CORK_NIL;
auxil->found_syntax_error = false;
}
static void ctxFini (struct parserCtx *auxil)
{
popKind (auxil, false);
intArrayDelete (auxil->kind_stack);
}
static void findVarlinkTags (void)
{
struct parserCtx auxil;
ctxInit (&auxil);
pvarlink_context_t *pctx = pvarlink_create(&auxil);
while (pvarlink_parse(pctx, NULL) && (!auxil.found_syntax_error) );
pvarlink_destroy(pctx);
ctxFini (&auxil);
}
extern parserDefinition* VarlinkParser (void)
{
static const char *const extensions [] = { "varlink", NULL };
parserDefinition* def = parserNew ("Varlink");
def->kindTable = VarlinkKinds;
def->kindCount = ARRAY_SIZE (VarlinkKinds);
def->extensions = extensions;
def->parser = findVarlinkTags;
def->useCork = true;
def->enabled = true;
def->defaultScopeSeparator = ".";
return def;
}
|