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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
/*
* Copyright (c) 2011, Colomban Wendling <colomban@geany.org>
*
* 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 for generating tags for Autoconf files.
*/
#include "general.h" /* must always come first */
#include <string.h>
#include "autoconf.h"
#include "m4.h"
#include "debug.h"
#include "entry.h"
#include "read.h"
#include "keyword.h"
#include "kind.h"
#include "parse.h"
static roleDefinition AutoconfOptwithRoles [] = {
{ true, "cmdline", "specified in a configure command line" },
};
static roleDefinition AutoconfOptenableRoles [] = {
{ true, "cmdline", "specified in a configure command line" },
};
static kindDefinition AutoconfKinds[] = {
{ true, 'p', "package", "packages" },
{ true, 't', "template", "templates" },
{ true, 'm', "macro", "autoconf macros" },
{ true, 'w', "optwith", "options specified with --with-...",
.referenceOnly = false, ATTACH_ROLES(AutoconfOptwithRoles)},
{ true, 'e', "optenable", "options specified with --enable-...",
.referenceOnly = false, ATTACH_ROLES(AutoconfOptenableRoles)},
{ true, 's', "subst", "substitution keys"},
{ true, 'c', "condition", "automake conditions" },
{ true, 'd', "definition", "definitions" },
};
typedef enum {
KEYWORD_init,
KEYWORD_template,
KEYWORD_defun,
KEYWORD_argwith,
KEYWORD_argenable,
KEYWORD_subst,
KEYWORD_conditional,
KEYWORD_define,
} autoconfKeywordId;
static const keywordTable autoconfKeywordTable[] = {
{ "AC_INIT", KEYWORD_init, },
{ "AH_TEMPLATE", KEYWORD_template, },
{ "AC_DEFUN", KEYWORD_defun, },
{ "AC_DEFUN_ONCE", KEYWORD_defun, },
{ "AC_ARG_WITH", KEYWORD_argwith, },
{ "AC_ARG_ENABLE", KEYWORD_argenable, },
{ "AC_SUBST", KEYWORD_subst, },
{ "AM_CONDITIONAL", KEYWORD_conditional, },
{ "AC_DEFINE", KEYWORD_define, },
{ "AC_DEFINE_UNQUOTED", KEYWORD_define, },
};
static bool doesLineCommentStart (m4Subparser *m4 CTAGS_ATTR_UNUSED, int c, const char* token CTAGS_ATTR_UNUSED)
{
return (c == '#');
}
static bool doesStringLiteralStart (m4Subparser *m4 CTAGS_ATTR_UNUSED, int c CTAGS_ATTR_UNUSED)
{
// return (c == '"') || (c == '\'') || (c == '`');
return false;
}
static bool probeLanguage (m4Subparser *m4 CTAGS_ATTR_UNUSED, const char* token)
{
return strncmp (token, "m4_", 3) == 0
|| strncmp (token, "AC_", 3) == 0
|| strncmp (token, "AM_", 3) == 0
|| strncmp (token, "AS_", 3) == 0
|| strncmp (token, "AH_", 3) == 0
;
}
static int makeAutoconfTag (int kind)
{
int index = CORK_NIL;
vString * name;
name = vStringNew();
readM4MacroArgument(name);
if (vStringLength (name) > 0)
{
tagEntryInfo e;
initTagEntry (&e, vStringValue(name), kind);
index = makeTagEntry(&e);
}
vStringDelete (name);
return index;
}
static int newMacroCallback (m4Subparser *m4 CTAGS_ATTR_UNUSED, const char* token)
{
int keyword;
int index = CORK_NIL;
keyword = lookupKeyword (token, getInputLanguage ());
/* TODO:
AH_VERBATIM
*/
switch (keyword)
{
case KEYWORD_NONE:
break;
case KEYWORD_init:
index = makeAutoconfTag (AUTOCONF_PACKAGE_KIND);
break;
case KEYWORD_template:
index = makeAutoconfTag (AUTOCONF_TEMPLATE_KIND);
break;
case KEYWORD_defun:
index = makeAutoconfTag (AUTOCONF_MACRO_KIND);
break;
case KEYWORD_argwith:
index = makeAutoconfTag (AUTOCONF_OPTWITH_KIND);
break;
case KEYWORD_argenable:
index = makeAutoconfTag (AUTOCONF_OPTENABLE_KIND);
break;
case KEYWORD_subst:
index = makeAutoconfTag (AUTOCONF_SUBST_KIND);
break;
case KEYWORD_conditional:
index = makeAutoconfTag (AUTOCONF_CONDITION_KIND);
break;
case KEYWORD_define:
index = makeAutoconfTag (AUTOCONF_DEFINITION_KIND);
break;
default:
AssertNotReached ();
}
return index;
}
static void exclusiveSubparserChosenCallback (subparser *s CTAGS_ATTR_UNUSED, void *data CTAGS_ATTR_UNUSED)
{
setM4Quotes ('[', ']');
}
static void findAutoconfTags(void)
{
scheduleRunningBaseparser (0);
}
extern parserDefinition* AutoconfParser (void)
{
static const char *const patterns [] = { "configure.in", NULL };
static const char *const extensions [] = { "ac", NULL };
parserDefinition* const def = parserNew("Autoconf");
static m4Subparser autoconfSubparser = {
.subparser = {
.direction = SUBPARSER_BI_DIRECTION,
.exclusiveSubparserChosenNotify = exclusiveSubparserChosenCallback,
},
.probeLanguage = probeLanguage,
.newMacroNotify = newMacroCallback,
.doesLineCommentStart = doesLineCommentStart,
.doesStringLiteralStart = doesStringLiteralStart,
};
static parserDependency dependencies [] = {
[0] = { DEPTYPE_SUBPARSER, "M4", &autoconfSubparser },
};
def->dependencies = dependencies;
def->dependencyCount = ARRAY_SIZE (dependencies);
def->kindTable = AutoconfKinds;
def->kindCount = ARRAY_SIZE(AutoconfKinds);
def->patterns = patterns;
def->extensions = extensions;
def->parser = findAutoconfTags;
def->useCork = CORK_QUEUE;
def->keywordTable = autoconfKeywordTable;
def->keywordCount = ARRAY_SIZE (autoconfKeywordTable);
return def;
}
|