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