Doxygen
Loading...
Searching...
No Matches
defargs.l
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2026 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16/*! \file
17 * This scanner is used to convert a string into a list of function or
18 * template arguments. Each parsed argument results in a Argument struct,
19 * that is put into an ArgumentList in declaration order.
20 * Comment blocks for arguments can also be included in the string.
21 * The argument string does not contain new-lines (except inside any
22 * comment blocks).
23 * An Argument consists of the string fields:
24 * type,name,default value, and documentation
25 * The Argument list as a whole can be pure, constant or volatile.
26 *
27 * Examples of input strings are:
28 * \verbatim
29 * "(int a,int b) const"
30 * "(const char *s="hello world",int=5) = 0"
31 * "<class T,class N>"
32 * "(char c,const char)"
33 * \endverbatim
34 *
35 * Note: It is not always possible to distinguish between the name and
36 * type of an argument. In case of doubt the name is added to the
37 * type, and the matchArgumentList in util.cpp is be used to
38 * further determine the correct separation.
39 */
40%option never-interactive
41%option prefix="defargsYY"
42%option reentrant
43%option extra-type="struct defargsYY_state *"
44%top{
45#include <stdint.h>
46// forward declare yyscan_t to improve type safety
47#define YY_TYPEDEF_YY_SCANNER_T
48struct yyguts_t;
49typedef yyguts_t *yyscan_t;
yyguts_t * yyscan_t
Definition code.l:24
50}
51
52%{
53
54// own header
55#include "defargs.h"
56
57// other includes
58#include "arguments.h"
59#include "debug.h"
60#include "entry.h"
61#include "message.h"
62#include "util.h"
63
64#define YY_NO_INPUT 1
65#define YY_NO_UNISTD_H 1
66
67/* -----------------------------------------------------------------
68 * state variables
69 */
97
98[[maybe_unused]] static const char *stateToString(int state);
99
100static int yyread(yyscan_t yyscanner,char *buf,int max_size);
101static bool nameIsActuallyPartOfType(DString &name);
102
103/* -----------------------------------------------------------------
104 */
105#undef YY_INPUT
106#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
107
108// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
109static inline const char *getLexerFILE() {return __FILE__;}
110#define LEX_NO_INPUT_FILENAME
111#include "doxygen_lex.h"
112
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
static bool nameIsActuallyPartOfType(DString &name)
Definition defargs.l:809
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
Definition defargs.l:632
static const char * stateToString(int state)
static const char * getLexerFILE()
Definition defargs.l:109
DString curArgDefValue
Definition defargs.l:80
const char * inputString
Definition defargs.l:74
std::unique_ptr< ArgumentList > & argList
Definition defargs.l:75
int argSquareCount
Definition defargs.l:88
DString curArgArray
Definition defargs.l:84
DString curArgDocs
Definition defargs.l:82
DString curArgName
Definition defargs.l:81
SrcLangExt lang
Definition defargs.l:76
defargsYY_state(const char *inStr, std::unique_ptr< ArgumentList > &al, SrcLangExt l)
Definition defargs.l:72
DString curArgAttrib
Definition defargs.l:83
DString * copyArgValue
Definition defargs.l:78
DString delimiter
Definition defargs.l:95
int lastExtendsContext
Definition defargs.l:94
DString extraTypeChars
Definition defargs.l:86
int argCurlyCount
Definition defargs.l:90
int readArgContext
Definition defargs.l:91
int argSharpCount
Definition defargs.l:89
DString curTypeConstraint
Definition defargs.l:85
int argRoundCount
Definition defargs.l:87
int inputPosition
Definition defargs.l:77
int lastDocContext
Definition defargs.l:92
DString curArgTypeName
Definition defargs.l:79
SrcLangExt
Definition types.h:207
A bunch of utility functions.
113%}
114
115B [ \t]
116Bopt {B}*
117ID [$a-z_A-Z\x80-\xFF][$a-z_A-Z0-9\x80-\xFF]*
118RAWBEGIN (u|U|L|u8)?R\"[^ \t\‍(\‍)\\‍]{0,16}"("
119RAWEND ")"[^ \t\‍(\‍)\\‍]{0,16}\"
120
121 // C start comment
122CCS "/\*"
123 // C end comment
124CCE "*\/"
125 // Cpp comment
126CPPC "/\/"
127
128%option noyywrap
129
130%x Start
131%x CopyArgString
132%x CopyRawString
133%x CopyArgRound
134%x CopyArgRound2
135%x CopyArgSquare
136%x CopyArgSharp
137%x CopyArgCurly
138%x ReadFuncArgType
139%x ReadFuncArgDef
140%x ReadFuncArgPtr
141%x FuncQual
142%x ReadDocBlock
143%x ReadDocLine
144%x ReadTypeConstraint
145%x TrailingReturn
146
147
149
150<Start>[<(] { BEGIN(ReadFuncArgType); }
151
152<ReadFuncArgType>{B}* {
153 yyextra->curArgTypeName+=" ";
154 }
155<ReadFuncArgType,ReadFuncArgPtr>"["[^\‍]]*"]" {
156 if (YY_START==ReadFuncArgPtr)
157 {
158 yyextra->curArgTypeName+=yytext;
159 }
160 else if (yyextra->curArgTypeName.stripWhiteSpace().empty())
161 {
162 yyextra->curArgAttrib=yytext; // for M$-IDL
163 }
164 else // array type
165 {
166 yyextra->curArgArray+=yytext;
167 }
168 }
169<ReadFuncArgDef>"'"\\‍[0-7]{1,3}"'" { yyextra->curArgDefValue+=yytext; }
170<ReadFuncArgDef>"'"\\."'" { yyextra->curArgDefValue+=yytext; }
171<ReadFuncArgDef>"'"."'" { yyextra->curArgDefValue+=yytext; }
172<ReadFuncArgDef>{RAWBEGIN} { yyextra->curArgDefValue+=yytext;
173 yyextra->delimiter = extractBeginRawStringDelimiter(yytext);
174 BEGIN( CopyRawString );
175 }
DString extractBeginRawStringDelimiter(const char *rawStart)
Definition util.cpp:5354
176<ReadFuncArgDef>\" {
177 yyextra->curArgDefValue+=*yytext;
178 BEGIN( CopyArgString );
179 }
180<ReadFuncArgType>"("([^:)]+{B}*"::")*{B}*[&*\^]+{Bopt}/{ID} {
181 // function pointer as argument
182 yyextra->curArgTypeName+=yytext;
183 //yyextra->curArgTypeName=yyextra->curArgTypeName.simplifyWhiteSpace();
184 BEGIN( ReadFuncArgPtr );
185 }
186<ReadFuncArgPtr>{ID} {
187 yyextra->curArgName=yytext;
188 }
189<ReadFuncArgPtr>")"{B}*"(" { // function pointer
190 yyextra->curArgTypeName+=yytext;
191 //yyextra->curArgTypeName=yyextra->curArgTypeName.simplifyWhiteSpace();
192 yyextra->readArgContext = ReadFuncArgType;
193 yyextra->copyArgValue=&yyextra->curArgTypeName;
194 yyextra->argRoundCount=0;
195 BEGIN( CopyArgRound2 );
196 }
197<ReadFuncArgPtr>")"/{B}*"[" { // pointer to fixed size array
198 yyextra->curArgTypeName+=yytext;
199 yyextra->curArgTypeName+=yyextra->curArgName;
200 //yyextra->curArgTypeName=yyextra->curArgTypeName.simplifyWhiteSpace();
201 BEGIN( ReadFuncArgType );
202 }
203<ReadFuncArgPtr>")" { // redundant braces detected / remove them
204 size_t i=yyextra->curArgTypeName.rfind('(');
205 size_t l=yyextra->curArgTypeName.length();
206 if (i!=DString::npos)
207 {
208 yyextra->curArgTypeName=yyextra->curArgTypeName.left(i)+
209 yyextra->curArgTypeName.right(l-i-1);
210 }
211 yyextra->curArgTypeName+=yyextra->curArgName;
212 BEGIN( ReadFuncArgType );
213 }
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
214<ReadFuncArgType>"<="|">="|"->"|">>"|"<<" { // handle operators in defargs
215 yyextra->curArgTypeName+=yytext;
216 }
217<ReadFuncArgType,ReadFuncArgDef>[({<\‍[] {
218 if (YY_START==ReadFuncArgType)
219 {
220 yyextra->curArgTypeName+=*yytext;
221 yyextra->copyArgValue=&yyextra->curArgTypeName;
222 }
223 else // YY_START==ReadFuncArgDef
224 {
225 yyextra->curArgDefValue+=*yytext;
226 yyextra->copyArgValue=&yyextra->curArgDefValue;
227 }
228 yyextra->readArgContext = YY_START;
229 if (*yytext=='(')
230 {
231 yyextra->argRoundCount=0;
232 BEGIN( CopyArgRound );
233 }
234 else if (*yytext=='[')
235 {
236 yyextra->argSquareCount=0;
237 BEGIN( CopyArgSquare );
238 }
239 else if (*yytext=='{')
240 {
241 yyextra->argCurlyCount=0;
242 BEGIN( CopyArgCurly );
243 }
244 else // yytext=='<'
245 {
246 yyextra->argSharpCount=0;
247 yyextra->argRoundCount=0;
248 BEGIN( CopyArgSharp );
249 }
250 }
251<CopyArgRound,CopyArgRound2>"(" {
252 yyextra->argRoundCount++;
253 *yyextra->copyArgValue += *yytext;
254 }
255<CopyArgRound,CopyArgRound2>")"({B}*{ID})* {
256 *yyextra->copyArgValue += yytext;
257 if (yyextra->argRoundCount>0)
258 {
259 yyextra->argRoundCount--;
260 }
261 else
262 {
263 if (YY_START==CopyArgRound2)
264 {
265 *yyextra->copyArgValue+=" "+yyextra->curArgName;
266 }
267 BEGIN( yyextra->readArgContext );
268 }
269 }
270<CopyArgRound>")"/{B}* {
271 *yyextra->copyArgValue += *yytext;
272 if (yyextra->argRoundCount>0) yyextra->argRoundCount--;
273 else BEGIN( yyextra->readArgContext );
274 }
275<CopyArgSquare>"[" {
276 yyextra->argSquareCount++;
277 *yyextra->copyArgValue += *yytext;
278 }
279<CopyArgSquare>"]"({B}*{ID})* {
280 *yyextra->copyArgValue += yytext;
281 if (yyextra->argSquareCount>0)
282 {
283 yyextra->argRoundCount--;
284 }
285 else
286 {
287 BEGIN( yyextra->readArgContext );
288 }
289 }
290<CopyArgSquare>"]"/{B}* {
291 *yyextra->copyArgValue += *yytext;
292 if (yyextra->argSquareCount>0) yyextra->argSquareCount--;
293 else BEGIN( yyextra->readArgContext );
294 }
295<CopyArgSharp>"<<" {
296 if (yyextra->argRoundCount>0)
297 {
298 // for e.g. < typename A = (i<<3) >
299 *yyextra->copyArgValue += yytext;
300 }
301 else
302 {
303 REJECT;
304 }
305 }
306<CopyArgSharp>">>" {
307 if (yyextra->argRoundCount>0)
308 {
309 // for e.g. < typename A = (i>>3) >
310 *yyextra->copyArgValue += yytext;
311 }
312 else
313 {
314 REJECT;
315 }
316 }
317<CopyArgSharp>"<" {
318 // don't count < inside (, e.g. for things like: < typename A=(i<6) >
319 if (yyextra->argRoundCount==0) yyextra->argSharpCount++;
320 *yyextra->copyArgValue += *yytext;
321 }
322<CopyArgSharp>">" {
323 *yyextra->copyArgValue += *yytext;
324 if (yyextra->argRoundCount>0 && yyextra->argSharpCount==0)
325 {
326 // don't count > inside )
327 }
328 else
329 {
330 if (yyextra->argSharpCount>0)
331 {
332 yyextra->argSharpCount--;
333 }
334 else
335 {
336 BEGIN( yyextra->readArgContext );
337 }
338 }
339 }
340<CopyArgSharp>"(" {
341 yyextra->argRoundCount++;
342 *yyextra->copyArgValue += *yytext;
343 }
344<CopyArgSharp>")" {
345 yyextra->argRoundCount--;
346 *yyextra->copyArgValue += *yytext;
347 }
348<CopyArgCurly>"{" {
349 yyextra->argCurlyCount++;
350 *yyextra->copyArgValue += *yytext;
351 }
352<CopyArgCurly>"}" {
353 *yyextra->copyArgValue += *yytext;
354 if (yyextra->argCurlyCount>0) yyextra->argCurlyCount--;
355 else BEGIN( yyextra->readArgContext );
356 }
357<CopyArgString>\\. {
358 yyextra->curArgDefValue+=yytext;
359 }
360<CopyRawString>{RAWEND} {
361 yyextra->curArgDefValue+=yytext;
362 if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
363 {
364 BEGIN( ReadFuncArgDef );
365 }
366 }
DString extractEndRawStringDelimiter(const char *rawEnd)
Definition util.cpp:5362
367<CopyArgString>\" {
368 yyextra->curArgDefValue+=*yytext;
369 BEGIN( ReadFuncArgDef );
370 }
371<ReadFuncArgType>"=" {
372 BEGIN( ReadFuncArgDef );
373 }
374<ReadFuncArgType,ReadFuncArgDef>[,)>]{B}*({CCS}[*!]|{CPPC}[/!])"<" {
375 yyextra->lastDocContext=YY_START;
376 yyextra->lastDocChar=*yytext;
377 DString text(yytext);
378 if (text.find("//")!=DString::npos)
379 BEGIN( ReadDocLine );
380 else
381 BEGIN( ReadDocBlock );
382 }
383<ReadFuncArgType,ReadFuncArgDef>[,)>] {
384 if (*yytext==')' && yyextra->curArgTypeName.stripWhiteSpace().empty())
385 {
386 yyextra->curArgTypeName+=*yytext;
387 BEGIN(FuncQual);
388 }
389 else
390 {
391 yyextra->curArgTypeName=removeRedundantWhiteSpace(yyextra->curArgTypeName);
392 yyextra->curArgDefValue=yyextra->curArgDefValue.stripWhiteSpace();
393 //printf("curArgType='%s' curArgDefVal='%s'\n",qPrint(yyextra->curArgTypeName),qPrint(yyextra->curArgDefValue));
394 int l = static_cast<int>(yyextra->curArgTypeName.length());
395 if (l>0)
396 {
397 int i=l-1;
398 while (i>=0 && (isspace((uint8_t)yyextra->curArgTypeName.at(i)) || yyextra->curArgTypeName.at(i)=='.')) i--;
399 while (i>=0 && (isId(yyextra->curArgTypeName.at(i)) || yyextra->curArgTypeName.at(i)=='$')) i--;
400 Argument a;
401 a.attrib = yyextra->curArgAttrib;
402 a.typeConstraint = yyextra->curTypeConstraint.stripWhiteSpace();
403 //printf("a->type=%s a->name=%s i=%d l=%d\n",
404 // qPrint(a->type),qPrint(a->name),i,l);
405 a.array.clear();
406 if (i==l-1 && yyextra->curArgTypeName.at(i)==')') // function argument
407 {
408 size_t bis=yyextra->curArgTypeName.find('(');
409 int bi = bis!=DString::npos ? static_cast<int>(bis) : -1;
410 int fi = bi-1;
411 //printf("func arg fi=%d\n",fi);
412 while (fi>=0 && (isId(yyextra->curArgTypeName.at(fi)) || yyextra->curArgTypeName.at(fi)==':')) fi--;
413 if (fi>=0)
414 {
415 a.type = yyextra->curArgTypeName.left(fi+1);
416 a.name = yyextra->curArgTypeName.mid(fi+1,bi-fi-1).stripWhiteSpace();
417 a.array = yyextra->curArgTypeName.right(l-bi);
418 }
419 else
420 {
421 a.type = yyextra->curArgTypeName;
422 }
423 }
424 else if (i>=0 && yyextra->curArgTypeName.at(i)!=':')
425 { // type contains a name
426 a.type = removeRedundantWhiteSpace(yyextra->curArgTypeName.left(i+1)).stripWhiteSpace();
427 a.name = yyextra->curArgTypeName.right(l-i-1).stripWhiteSpace();
428
429 // if the type becomes a type specifier only then we make a mistake
430 // and need to correct it to avoid seeing a nameless parameter
431 // "struct A" as a parameter with type "struct" and name "A".
432 int sv=0;
433 if (a.type.startsWith("const ")) sv=6;
434 else if (a.type.startsWith("volatile ")) sv=9;
435
436 if (a.type.mid(sv)=="struct" ||
437 a.type.mid(sv)=="union" ||
438 a.type.mid(sv)=="class" ||
439 a.type.mid(sv)=="typename" ||
440 a.type=="const" ||
441 a.type=="volatile" ||
443 )
444 {
445 a.type = a.type + " " + a.name;
446 a.name.clear();
447 }
448 //printf(" --> a->type='%s' a->name='%s'\n",qPrint(a->type),qPrint(a->name));
449 }
450 else // assume only the type was specified, try to determine name later
451 {
452 a.type = removeRedundantWhiteSpace(yyextra->curArgTypeName);
453 }
454 if (!a.type.empty() && a.type.at(0)=='$') // typeless PHP name?
455 {
456 a.name = a.type;
457 a.type = "";
458 }
459 a.array += removeRedundantWhiteSpace(yyextra->curArgArray);
460 //printf("array=%s\n",qPrint(a->array));
461 size_t alen = a.array.length();
462 if (alen>2 && a.array.at(0)=='(' &&
463 a.array.at(alen-1)==')') // fix-up for int *(a[10])
464 {
465 size_t pi=a.array.find('[');
466 i = pi!=DString::npos ? static_cast<int>(pi-1) : -1;
467 a.array = a.array.mid(1,alen-2);
468 if (i>0 && a.name.empty())
469 {
470 a.name = a.array.left(i).stripWhiteSpace();
471 a.array = a.array.mid(i);
472 }
473 }
474 a.defval = yyextra->curArgDefValue;
475 //printf("a->type=%s a->name=%s a->defval=\"%s\"\n",qPrint(a->type),qPrint(a->name),qPrint(a->defval));
476 a.docs = yyextra->curArgDocs.stripWhiteSpace();
477 //printf("Argument '%s' '%s' adding docs='%s'\n",qPrint(a->type),qPrint(a->name),qPrint(a->docs));
478 yyextra->argList->push_back(a);
479 }
480 yyextra->curArgAttrib.clear();
481 yyextra->curArgTypeName.clear();
482 yyextra->curArgDefValue.clear();
483 yyextra->curArgArray.clear();
484 yyextra->curArgDocs.clear();
485 yyextra->curTypeConstraint.clear();
486 if (*yytext==')')
487 {
488 BEGIN(FuncQual);
489 //printf(">>> end of argument list\n");
490 }
491 else
492 {
493 BEGIN( ReadFuncArgType );
494 }
495 }
496 }
This class contains the information about the argument of a function or template.
Definition arguments.h:27
DString docs
Definition arguments.h:48
DString typeConstraint
Definition arguments.h:49
DString attrib
Definition arguments.h:42
DString defval
Definition arguments.h:47
DString array
Definition arguments.h:46
DString name
Definition arguments.h:45
DString type
Definition arguments.h:43
void clear()
Definition dstring.h:214
void push_back(char c)
Definition dstring.h:202
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
DString right(size_t len) const
Definition dstring.h:311
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
DString left(size_t len) const
Definition dstring.h:306
bool startsWith(const char *s) const
Definition dstring.h:600
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
bool isId(char c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:426
497<ReadFuncArgType,ReadFuncArgPtr>"extends" {
498 if (yyextra->lang!=SrcLangExt::Java)
499 {
500 REJECT;
501 }
502 else
503 {
504 yyextra->argSharpCount=0;
505 yyextra->curTypeConstraint.clear();
506 yyextra->lastExtendsContext=YY_START;
507 BEGIN(ReadTypeConstraint);
508 }
509 }
510<ReadFuncArgType,ReadFuncArgPtr>"$"?{ID} {
511 DString name(yytext);
512 if (YY_START==ReadFuncArgType && yyextra->curArgArray=="[]") // Java style array
513 {
514 yyextra->curArgTypeName+=" []";
515 yyextra->curArgArray.clear();
516 }
517 //printf("resolveName '%s'->'%s'\n",yytext,qPrint(name));
518 yyextra->curArgTypeName+=name;
519 }
520<ReadFuncArgType,ReadFuncArgPtr>. {
521 yyextra->curArgTypeName+=*yytext;
522 }
523
524<ReadFuncArgDef,CopyArgString>"<="|"->"|">="|">>"|"<<" {
525 yyextra->curArgDefValue+=yytext;
526 }
527<ReadFuncArgDef,CopyArgString,CopyRawString>. {
528 yyextra->curArgDefValue+=*yytext;
529 }
530<CopyArgRound,CopyArgRound2,CopyArgSquare,CopyArgSharp,CopyArgCurly>{ID} {
531 *yyextra->copyArgValue+=yytext;
532 }
533<CopyArgRound,CopyArgRound2,CopyArgSquare,CopyArgSharp,CopyArgCurly>. {
534 *yyextra->copyArgValue += *yytext;
535 }
536<ReadTypeConstraint>[,)>] {
537 if (yytext[0]!='>' || yyextra->argSharpCount==0)
538 {
539 unput(*yytext);
540 BEGIN(yyextra->lastExtendsContext);
541 }
542 else
543 {
544 yyextra->curTypeConstraint+=yytext;
545 yyextra->argSharpCount--;
546 }
547 }
548<ReadTypeConstraint>"<" {
549 yyextra->curTypeConstraint+=yytext;
550 yyextra->argSharpCount++;
551 }
552<ReadTypeConstraint>. {
553 yyextra->curTypeConstraint+=yytext;
554 }
555<ReadTypeConstraint>\n {
556 yyextra->curTypeConstraint+=' ';
557 }
558<FuncQual>"const" {
559 yyextra->argList->setConstSpecifier(true);
560 }
561<FuncQual>"volatile" {
562 yyextra->argList->setVolatileSpecifier(true);
563 }
564<FuncQual>"override" {
565 }
566<FuncQual>"&" {
567 yyextra->argList->setRefQualifier(RefQualifierType::LValue);
568 }
569<FuncQual>"&&" {
570 yyextra->argList->setRefQualifier(RefQualifierType::RValue);
571 }
572<FuncQual,TrailingReturn>"="{B}*"0" {
573 yyextra->argList->setPureSpecifier(true);
574 BEGIN(FuncQual);
575 }
576<FuncQual>"->" { // C++11 trailing return type
577 yyextra->argList->setTrailingReturnType(DString(" -> "));
578 BEGIN(TrailingReturn);
579 }
580<TrailingReturn>{B}/("final"|"override"){B}* {
581 unput(*yytext);
582 BEGIN(FuncQual);
583 }
584<TrailingReturn>. {
585 yyextra->argList->setTrailingReturnType(yyextra->argList->trailingReturnType()+yytext);
586 }
587<TrailingReturn>\n {
588 yyextra->argList->setTrailingReturnType(yyextra->argList->trailingReturnType()+yytext);
589 }
590<FuncQual>")"{B}*"["[^]]*"]" { // for functions returning a pointer to an array,
591 // i.e. ")[]" in "int (*f(int))[4]" with argsString="(int))[4]"
592 yyextra->extraTypeChars=yytext;
593 }
594<ReadDocBlock>[^\*\n]+ {
595 yyextra->curArgDocs+=yytext;
596 }
597<ReadDocLine>[^\n]+ {
598 yyextra->curArgDocs+=yytext;
599 }
600<ReadDocBlock>{CCE} {
601 if (yyextra->lastDocChar!=0)
602 unput(yyextra->lastDocChar);
603 BEGIN(yyextra->lastDocContext);
604 }
605<ReadDocLine>\n {
606 if (yyextra->lastDocChar!=0)
607 unput(yyextra->lastDocChar);
608 BEGIN(yyextra->lastDocContext);
609 }
610<ReadDocBlock>\n {
611 yyextra->curArgDocs+=*yytext;
612 }
613<ReadDocBlock>. {
614 yyextra->curArgDocs+=*yytext;
615 }
616<*>({CCS}[*!]|{CPPC}[/!])("<"?) {
617 yyextra->lastDocContext=YY_START;
618 yyextra->lastDocChar=0;
619 if (yytext[1]=='/')
620 BEGIN( ReadDocLine );
621 else
622 BEGIN( ReadDocBlock );
623 }
624<*>\n
625<*>.
626
627%%
628
629/* ----------------------------------------------------------------------------
630 */
631
632static int yyread(yyscan_t yyscanner,char *buf,int max_size)
633{
634 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
635 int c=0;
636 while( c < max_size && yyextra->inputString[yyextra->inputPosition] )
637 {
638 *buf = yyextra->inputString[yyextra->inputPosition++] ;
639 c++; buf++;
640 }
641 return c;
642}
643
644/*
645The following code is generated using 'gperf keywords.txt'
646where keywords.txt has the following content
647
648---------------------------------
649%define class-name KeywordHash
650%define lookup-function-name find
651%readonly-tables
652%language=C++
653%%
654unsigned
655signed
656bool
657char
658char8_t
659char16_t
660char32_t
661wchar_t
662int
663short
664long
665float
666double
667int8_t
668int16_t
669int32_t
670int64_t
671intmax_t
672intptr_t
673uint8_t
674uint16_t
675uint32_t
676uint64_t
677uintmax_t
678uintptr_t
679const
680volatile
681void
682%%
683---------------------------------
684*/
685//--- begin gperf generated code ----------------------------------------------------------
686
687#define TOTAL_KEYWORDS 28
688#define MIN_WORD_LENGTH 3
689#define MAX_WORD_LENGTH 9
690#define MIN_HASH_VALUE 3
691#define MAX_HASH_VALUE 48
692/* maximum key range = 46, duplicates = 0 */
693
695{
696 private:
697 static inline size_t hash (const char *str, size_t len);
698 public:
699 static const char *find (const char *str, size_t len);
700};
701
702inline size_t KeywordHash::hash (const char *str, size_t len)
703{
704 static const unsigned char asso_values[] =
705 {
706 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
707 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
708 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
709 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
710 49, 49, 49, 49, 49, 49, 49, 49, 49, 5,
711 5, 30, 0, 49, 25, 49, 10, 49, 49, 49,
712 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
713 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
714 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
715 49, 49, 49, 49, 49, 0, 49, 0, 5, 49,
716 15, 0, 49, 10, 49, 30, 49, 49, 0, 20,
717 0, 49, 15, 49, 5, 10, 0, 49, 49, 49,
718 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
719 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
720 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
721 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
722 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
723 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
724 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
725 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
726 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
727 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
728 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
729 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
730 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
731 49, 49, 49, 49, 49, 49
732 };
733 size_t hval = len;
734
735 switch (hval)
736 {
737 default:
738 hval += asso_values[static_cast<unsigned char>(str[4])];
739 /*FALLTHROUGH*/
740 case 4:
741 hval += asso_values[static_cast<unsigned char>(str[3])];
742 /*FALLTHROUGH*/
743 case 3:
744 break;
745 }
746 return hval;
747}
748
749const char * KeywordHash::find (const char *str, size_t len)
750{
751 static const char * const wordlist[] =
752 {
753 "", "", "",
754 "int",
755 "bool",
756 "float",
757 "signed",
758 "",
759 "volatile",
760 "char",
761 "short",
762 "double",
763 "wchar_t",
764 "uint16_t",
765 "long",
766 "const",
767 "int8_t",
768 "uint8_t",
769 "char16_t",
770 "void",
771 "", "",
772 "char8_t",
773 "intptr_t",
774 "uintptr_t",
775 "", "", "",
776 "intmax_t",
777 "uintmax_t",
778 "", "",
779 "int64_t",
780 "uint64_t",
781 "", "", "",
782 "int16_t",
783 "uint32_t",
784 "", "", "",
785 "int32_t",
786 "char32_t",
787 "", "", "", "",
788 "unsigned"
789 };
790
791 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
792 {
793 size_t key = hash (str, len);
794
795 if (key <= MAX_HASH_VALUE)
796 {
797 const char *s = wordlist[key];
798
799 if (*str == *s && !dstrcmp (str + 1, s + 1))
800 return s;
801 }
802 }
803 return nullptr;
804}
805
806//--- end gperf generated code ----------------------------------------------------------
807
808/* bug_520975 */
810{
811 return KeywordHash::find(name.data(),name.length())!=nullptr;
812}
813
814/*! Converts an argument string into an ArgumentList.
815 * \param[in] lang language of the current argument list
816 * \param[in] argsString the list of Arguments.
817 * \param[out] extraTypeChars point to string to which trailing characters
818 * for complex types are written to
819 */
820
821std::unique_ptr<ArgumentList> stringToArgumentList(SrcLangExt lang, const DString &argsString,DString *extraTypeChars)
822{
823 std::unique_ptr<ArgumentList> al = std::make_unique<ArgumentList>();
824 if (argsString.empty()) return al;
825
826 yyscan_t yyscanner;
827 defargsYY_state extra(argsString.data(),al,lang);
828 defargsYYlex_init_extra(&extra,&yyscanner);
829#ifdef FLEX_DEBUG
830 defargsYYset_debug(Debug::isFlagSet(Debug::Lex_defargs)?1:0,yyscanner);
831#endif
832 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
833 DebugLex debugLex(Debug::Lex_defargs, __FILE__, nullptr);
834
835 defargsYYrestart( nullptr, yyscanner );
836 BEGIN( Start );
837 defargsYYlex(yyscanner);
838 if (yyextra->argList->empty())
839 {
840 yyextra->argList->setNoParameters(true);
841 }
842 if (extraTypeChars) *extraTypeChars=yyextra->extraTypeChars;
843 //printf("stringToArgumentList(%s) result=%s\n",argsString,qPrint(argListToString(*al)));
844 defargsYYlex_destroy(yyscanner);
845 return al;
846}
847
848#include "defargs.l.h"
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
@ Lex_defargs
Definition debug.h:60
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
static size_t hash(const char *str, size_t len)
Definition defargs.l:702
static const char * find(const char *str, size_t len)
Definition defargs.l:749
static int yyread(char *buf, int max_size, yyscan_t yyscanner)
Definition constexp.l:110
std::unique_ptr< ArgumentList > stringToArgumentList(SrcLangExt lang, const DString &argsString, DString *extraTypeChars)
Definition defargs.l:821
#define MIN_WORD_LENGTH
Definition defargs.l:688
#define MAX_HASH_VALUE
Definition defargs.l:691
int dstrcmp(const char *str1, const char *str2)
Definition dstring.h:50