File: perl-function-parameters.c

package info (click to toggle)
codelite 17.0.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 136,384 kB
  • sloc: cpp: 491,550; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 805; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (178 lines) | stat: -rw-r--r-- 4,286 bytes parent folder | download | duplicates (5)
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
/*
 *   Copyright (c) 2021, Masatake YAMATO
 *   Copyright (c) 2021, 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 for generating tags for Function::Parameters perl extension.
 *   https://metacpan.org/pod/Function::Parameters
 *
 *   This parser is inspired by the pull request submitted by Jim Butler (@jimmygoogle).
 */

/*
 *   INCLUDE FILES
 */
#include "general.h"  /* must always come first */

#include "entry.h"
#include "kind.h"
#include "parse.h"
#include "perl.h"

#include <string.h>

/*
 *   DATA DECLARATIONS
 */

enum FParamsKind {
	K_METHOD,
	K_FUN,
};

static kindDefinition FParamsKinds[] = {
	{ true, 'm', "method", "methods" },
	{ true, 'f', "fun",    "functions" },
};

struct FParamsSubparser {
	perlSubparser perl;
	bool notInFParams;
	bool inPod;
};

/*
 *   FUNCTION PROTOTYPES
 */

static void inputStart (subparser *s);
static void makeTagEntryNotify (subparser *s, const tagEntryInfo *tag, int corkIndex);
static void enterFParams (struct FParamsSubparser *fparms);
static void leaveFParams (struct FParamsSubparser *fparams);
static void enteringPodNotify (perlSubparser *perl);
static void leavingPodNotify  (perlSubparser *perl);

/*
 *   DATA DEFINITIONS
 */

static struct FParamsSubparser fparamsSubparser = {
	.perl = {
		.subparser = {
			.direction  = SUBPARSER_BI_DIRECTION,
			.inputStart = inputStart,
			.makeTagEntryNotify = makeTagEntryNotify,
		},
		.enteringPodNotify = enteringPodNotify,
		.leavingPodNotify  = leavingPodNotify,
	}
};

/*
 *   FUNCTION DEFINITIONS
 */

static void inputStart (subparser *s)
{
	struct FParamsSubparser *fparams = (struct FParamsSubparser *)s;

	fparams->notInFParams = true;
	fparams->inPod = false;
}

static void makeTagEntryNotify (subparser *s, const tagEntryInfo *tag, int corkIndex)
{
	perlSubparser *perl = (perlSubparser *)s;
	struct FParamsSubparser *fparams = (struct FParamsSubparser *)perl;

	if (isTagExtraBitMarked(tag, XTAG_QUALIFIED_TAGS))
		return;

	if (tag->kindIndex == KIND_PERL_MODULE)
	{
		if (isRoleAssigned(tag, ROLE_PERL_MODULE_USED)
			&& strcmp (tag->name, "Function::Parameters") == 0)
			enterFParams (fparams);
		else if (isRoleAssigned(tag, ROLE_PERL_MODULE_UNUSED)
				 && strcmp (tag->name, "Function::Parameters") == 0)
			leaveFParams (fparams);
	}
}

static void enterFParams (struct FParamsSubparser *fparams)
{
	fparams->notInFParams = false;
}

static void leaveFParams (struct FParamsSubparser *fparams)
{
	fparams->notInFParams = true;
}

static void enteringPodNotify (perlSubparser *perl)
{
	struct FParamsSubparser *fparams = (struct FParamsSubparser *)perl;
	fparams->inPod = true;
}

static void leavingPodNotify  (perlSubparser *perl)
{
	struct FParamsSubparser *fparams = (struct FParamsSubparser *)perl;
	fparams->inPod = false;
}

static bool findFParamsObject (const char * line, const regexMatch *matches, unsigned int count,
							   void *userData)
{
	struct FParamsSubparser *fparams = (struct FParamsSubparser *)userData;

	if (fparams->inPod)
		return false;


	const char *kindHint = line + matches[1].start;
	int kind = kindHint [0] == 'm'? K_METHOD: K_FUN;

	char *name = eStrndup (line + matches[2].start, matches[2].length);
	tagEntryInfo e;
	initTagEntry (&e, name, kind);

	makeTagEntry (&e);
	eFree (name);
	return true;
}

static void findFParamsTags (void)
{
	scheduleRunningBaseparser (RUN_DEFAULT_SUBPARSERS);
}

static void initializeFParamsParser (langType language)
{
	addLanguageCallbackRegex (language, "^[ \t]*(method|fun)[ \t]+([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*\\(",
							  NULL,
							  findFParamsObject, &fparamsSubparser.notInFParams,
							  &fparamsSubparser);
}

extern parserDefinition* FunctionParametersParser (void)
{
	parserDefinition* const def = parserNew("FunctionParameters");

	static parserDependency dependencies [] = {
		[0] = { DEPTYPE_SUBPARSER, "Perl", &fparamsSubparser },
	};

	def->dependencies = dependencies;
	def->dependencyCount = ARRAY_SIZE (dependencies);

	def->kindTable = FParamsKinds;
	def->kindCount = ARRAY_SIZE(FParamsKinds);

	def->initialize = initializeFParamsParser;
	def->parser = findFParamsTags;

	return def;
}