FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppcheck/lib/library.cpp at master · napcode/cppcheck · GitHub
napcode
/
cppcheck
Public
forked from
cppcheck-opensource/cppcheck
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppcheck
/
lib
/
library.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
1495 lines (1354 loc) · 63.3 KB
Breadcrumbs
cppcheck
/
lib
/
library.cpp
Copy path
File metadata and controls
1495 lines (1354 loc) · 63.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2019 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#
include
"
library.h
"
#
include
"
astutils.h
"
#
include
"
mathlib.h
"
#
include
"
path.h
"
#
include
"
symboldatabase.h
"
#
include
"
tinyxml2.h
"
#
include
"
token.h
"
#
include
"
tokenlist.h
"
#
include
"
utils.h
"
#
include
<
cctype
>
#
include
<
cstdlib
>
#
include
<
cstring
>
#
include
<
list
>
static
std::vector<std::string>
getnames
(
const
char
*names)
{
std::vector<std::string> ret;
while
(
const
char
*p =
std::strchr
(names,
'
,
'
)) {
ret.
emplace_back
(names, p-names);
names = p +
1
;
}
ret.
emplace_back
(names);
return
ret;
}
static
void
gettokenlistfromvalid
(
const
std::string& valid, TokenList& tokenList)
{
std::istringstream
istr
(valid +
'
,
'
);
tokenList.
createTokens
(istr);
for
(Token *tok = tokenList.
front
(); tok; tok = tok->
next
()) {
if
(
Token::Match
(tok,
"
- %num%
"
)) {
tok->
str
(
"
-
"
+ tok->
strAt
(
1
));
tok->
deleteNext
();
}
}
}
Library::Library
() : mAllocId(
0
)
{
}
Library::Error
Library::load
(
const
char
exename[],
const
char
path[])
{
if
(
std::strchr
(path,
'
,
'
) !=
nullptr
) {
std::string
p
(path);
for
(;;) {
const
std::string::size_type pos = p.
find
(
'
,
'
);
if
(pos == std::string::npos)
break
;
const
Error &e =
load
(exename, p.
substr
(
0
,pos).
c_str
());
if
(e.
errorcode
!=
OK
)
return
e;
p = p.
substr
(pos+
1
);
}
if
(!p.
empty
())
return
load
(exename, p.
c_str
());
return
Error
();
}
std::string absolute_path;
//
open file..
tinyxml2::XMLDocument doc;
tinyxml2::XMLError error = doc.
LoadFile
(path);
if
(error == tinyxml2::
XML_ERROR_FILE_READ_ERROR
&&
Path::getFilenameExtension
(path).
empty
())
//
Reading file failed, try again...
error = tinyxml2::
XML_ERROR_FILE_NOT_FOUND
;
if
(error == tinyxml2::
XML_ERROR_FILE_NOT_FOUND
) {
//
failed to open file.. is there no extension?
std::string
fullfilename
(path);
if
(
Path::getFilenameExtension
(fullfilename).
empty
()) {
fullfilename +=
"
.cfg
"
;
error = doc.
LoadFile
(fullfilename.
c_str
());
if
(error != tinyxml2::
XML_ERROR_FILE_NOT_FOUND
)
absolute_path =
Path::getAbsoluteFilePath
(fullfilename);
}
std::list<std::string> cfgfolders;
#
ifdef
FILESDIR
cfgfolders.
emplace_back
(
FILESDIR
"
/cfg
"
);
#
endif
if
(exename) {
const
std::string
exepath
(
Path::fromNativeSeparators
(
Path::getPathFromFilename
(exename)));
cfgfolders.
push_back
(exepath +
"
cfg
"
);
cfgfolders.
push_back
(exepath);
}
while
(error == tinyxml2::
XML_ERROR_FILE_NOT_FOUND
&& !cfgfolders.
empty
()) {
const
std::string
cfgfolder
(cfgfolders.
back
());
cfgfolders.
pop_back
();
const
char
*sep = (!cfgfolder.
empty
() &&
endsWith
(cfgfolder,
'
/
'
) ?
"
"
:
"
/
"
);
const
std::string
filename
(cfgfolder + sep + fullfilename);
error = doc.
LoadFile
(filename.
c_str
());
if
(error != tinyxml2::
XML_ERROR_FILE_NOT_FOUND
)
absolute_path =
Path::getAbsoluteFilePath
(filename);
}
}
else
absolute_path =
Path::getAbsoluteFilePath
(path);
if
(error == tinyxml2::
XML_SUCCESS
) {
if
(
mFiles
.
find
(absolute_path) ==
mFiles
.
end
()) {
Error err =
load
(doc);
if
(err.
errorcode
==
OK
)
mFiles
.
insert
(absolute_path);
return
err;
}
return
Error
(
OK
);
//
ignore duplicates
}
if
(error == tinyxml2::
XML_ERROR_FILE_NOT_FOUND
)
return
Error
(
FILE_NOT_FOUND
);
else
{
doc.
PrintError
();
return
Error
(
BAD_XML
);
}
}
bool
Library::loadxmldata
(
const
char
xmldata[], std::
size_t
len)
{
tinyxml2::XMLDocument doc;
return
(tinyxml2::
XML_SUCCESS
== doc.
Parse
(xmldata, len)) && (
load
(doc).
errorcode
==
OK
);
}
Library::Error
Library::load
(
const
tinyxml2::XMLDocument &doc)
{
const
tinyxml2::XMLElement *
const
rootnode = doc.
FirstChildElement
();
if
(rootnode ==
nullptr
) {
doc.
PrintError
();
return
Error
(
BAD_XML
);
}
if
(
strcmp
(rootnode->
Name
(),
"
def
"
) !=
0
)
return
Error
(
UNSUPPORTED_FORMAT
, rootnode->
Name
());
const
char
* format_string = rootnode->
Attribute
(
"
format
"
);
int
format =
1
;
//
Assume format version 1 if nothing else is specified (very old .cfg files had no 'format' attribute)
if
(format_string)
format =
atoi
(format_string);
if
(format >
2
|| format <=
0
)
return
Error
(
UNSUPPORTED_FORMAT
);
std::set<std::string> unknown_elements;
for
(
const
tinyxml2::XMLElement *node = rootnode->
FirstChildElement
(); node; node = node->
NextSiblingElement
()) {
const
std::string nodename = node->
Name
();
if
(nodename ==
"
memory
"
|| nodename ==
"
resource
"
) {
//
get allocationId to use..
int
allocationId =
0
;
for
(
const
tinyxml2::XMLElement *memorynode = node->
FirstChildElement
(); memorynode; memorynode = memorynode->
NextSiblingElement
()) {
if
(
strcmp
(memorynode->
Name
(),
"
dealloc
"
)==
0
) {
const
std::map<std::string, AllocFunc>::const_iterator it =
mDealloc
.
find
(memorynode->
GetText
());
if
(it !=
mDealloc
.
end
()) {
allocationId = it->
second
.
groupId
;
break
;
}
}
}
if
(allocationId ==
0
) {
if
(nodename ==
"
memory
"
)
while
(!
ismemory
(++
mAllocId
));
else
while
(!
isresource
(++
mAllocId
));
allocationId =
mAllocId
;
}
//
add alloc/dealloc/use functions..
for
(
const
tinyxml2::XMLElement *memorynode = node->
FirstChildElement
(); memorynode; memorynode = memorynode->
NextSiblingElement
()) {
const
std::string memorynodename = memorynode->
Name
();
if
(memorynodename ==
"
alloc
"
|| memorynodename ==
"
realloc
"
) {
AllocFunc temp = {
0
};
temp.
groupId
= allocationId;
if
(memorynode->
Attribute
(
"
init
"
,
"
false
"
))
returnuninitdata.
insert
(memorynode->
GetText
());
const
char
*arg = memorynode->
Attribute
(
"
arg
"
);
if
(arg)
temp.
arg
=
atoi
(arg);
else
temp.
arg
= -
1
;
const
char
*bufferSize = memorynode->
Attribute
(
"
buffer-size
"
);
if
(!bufferSize)
temp.
bufferSize
= AllocFunc::BufferSize::none;
else
{
if
(
std::strncmp
(bufferSize,
"
malloc
"
,
6
) ==
0
)
temp.
bufferSize
= AllocFunc::BufferSize::malloc;
else
if
(
std::strncmp
(bufferSize,
"
calloc
"
,
6
) ==
0
)
temp.
bufferSize
= AllocFunc::BufferSize::calloc;
else
if
(
std::strncmp
(bufferSize,
"
strdup
"
,
6
) ==
0
)
temp.
bufferSize
= AllocFunc::BufferSize::strdup;
else
return
Error
(
BAD_ATTRIBUTE_VALUE
, bufferSize);
temp.
bufferSizeArg1
=
1
;
temp.
bufferSizeArg2
=
2
;
if
(bufferSize[
6
] ==
0
) {
//
use default values
}
else
if
(bufferSize[
6
] ==
'
:
'
&& bufferSize[
7
] >=
'
1
'
&& bufferSize[
7
] <=
'
5
'
) {
temp.
bufferSizeArg1
= bufferSize[
7
] -
'
0
'
;
if
(bufferSize[
8
] ==
'
,
'
&& bufferSize[
9
] >=
'
1
'
&& bufferSize[
9
] <=
'
5
'
)
temp.
bufferSizeArg2
= bufferSize[
9
] -
'
0
'
;
}
else
return
Error
(
BAD_ATTRIBUTE_VALUE
, bufferSize);
}
if
(memorynodename ==
"
realloc
"
) {
const
char
*reallocArg = memorynode->
Attribute
(
"
realloc-arg
"
);
if
(reallocArg)
temp.
reallocArg
=
atoi
(reallocArg);
else
temp.
reallocArg
=
1
;
}
if
(memorynodename !=
"
realloc
"
)
mAlloc
[memorynode->
GetText
()] = temp;
else
mRealloc
[memorynode->
GetText
()] = temp;
}
else
if
(memorynodename ==
"
dealloc
"
) {
AllocFunc temp = {
0
};
temp.
groupId
= allocationId;
const
char
*arg = memorynode->
Attribute
(
"
arg
"
);
if
(arg)
temp.
arg
=
atoi
(arg);
else
temp.
arg
=
1
;
mDealloc
[memorynode->
GetText
()] = temp;
}
else
if
(memorynodename ==
"
use
"
)
functions[memorynode->
GetText
()].
use
=
true
;
else
unknown_elements.
insert
(memorynodename);
}
}
else
if
(nodename ==
"
define
"
) {
const
char
*name = node->
Attribute
(
"
name
"
);
if
(name ==
nullptr
)
return
Error
(
MISSING_ATTRIBUTE
,
"
name
"
);
const
char
*value = node->
Attribute
(
"
value
"
);
if
(value ==
nullptr
)
return
Error
(
MISSING_ATTRIBUTE
,
"
value
"
);
defines.
push_back
(
std::string
(name) +
"
"
+
value);
}
else
if
(nodename ==
"
function
"
) {
const
char
*name = node->
Attribute
(
"
name
"
);
if
(name ==
nullptr
)
return
Error
(
MISSING_ATTRIBUTE
,
"
name
"
);
for
(
const
std::string &s :
getnames
(name)) {
const
Error &err =
loadFunction
(node, s, unknown_elements);
if
(err.
errorcode
!= ErrorCode::
OK
)
return
err;
}
}
else
if
(nodename ==
"
reflection
"
) {
for
(
const
tinyxml2::XMLElement *reflectionnode = node->
FirstChildElement
(); reflectionnode; reflectionnode = reflectionnode->
NextSiblingElement
()) {
if
(
strcmp
(reflectionnode->
Name
(),
"
call
"
) !=
0
) {
unknown_elements.
insert
(reflectionnode->
Name
());
continue
;
}
const
char
*
const
argString = reflectionnode->
Attribute
(
"
arg
"
);
if
(!argString)
return
Error
(
MISSING_ATTRIBUTE
,
"
arg
"
);
mReflection
[reflectionnode->
GetText
()] =
atoi
(argString);
}
}
else
if
(nodename ==
"
markup
"
) {
const
char
*
const
extension = node->
Attribute
(
"
ext
"
);
if
(!extension)
return
Error
(
MISSING_ATTRIBUTE
,
"
ext
"
);
mMarkupExtensions
.
insert
(extension);
mReportErrors
[extension] = (node->
Attribute
(
"
reporterrors
"
,
"
true
"
) !=
nullptr
);
mProcessAfterCode
[extension] = (node->
Attribute
(
"
aftercode
"
,
"
true
"
) !=
nullptr
);
for
(
const
tinyxml2::XMLElement *markupnode = node->
FirstChildElement
(); markupnode; markupnode = markupnode->
NextSiblingElement
()) {
const
std::string markupnodename = markupnode->
Name
();
if
(markupnodename ==
"
keywords
"
) {
for
(
const
tinyxml2::XMLElement *librarynode = markupnode->
FirstChildElement
(); librarynode; librarynode = librarynode->
NextSiblingElement
()) {
if
(
strcmp
(librarynode->
Name
(),
"
keyword
"
) ==
0
) {
const
char
* nodeName = librarynode->
Attribute
(
"
name
"
);
if
(nodeName ==
nullptr
)
return
Error
(
MISSING_ATTRIBUTE
,
"
name
"
);
mKeywords
[extension].
insert
(nodeName);
}
else
unknown_elements.
insert
(librarynode->
Name
());
}
}
else
if
(markupnodename ==
"
exported
"
) {
for
(
const
tinyxml2::XMLElement *exporter = markupnode->
FirstChildElement
(); exporter; exporter = exporter->
NextSiblingElement
()) {
if
(
strcmp
(exporter->
Name
(),
"
exporter
"
) !=
0
) {
unknown_elements.
insert
(exporter->
Name
());
continue
;
}
const
char
*
const
prefix = exporter->
Attribute
(
"
prefix
"
);
if
(!prefix)
return
Error
(
MISSING_ATTRIBUTE
,
"
prefix
"
);
for
(
const
tinyxml2::XMLElement *e = exporter->
FirstChildElement
(); e; e = e->
NextSiblingElement
()) {
const
std::string ename = e->
Name
();
if
(ename ==
"
prefix
"
)
mExporters
[prefix].
addPrefix
(e->
GetText
());
else
if
(ename ==
"
suffix
"
)
mExporters
[prefix].
addSuffix
(e->
GetText
());
else
unknown_elements.
insert
(ename);
}
}
}
else
if
(markupnodename ==
"
imported
"
) {
for
(
const
tinyxml2::XMLElement *librarynode = markupnode->
FirstChildElement
(); librarynode; librarynode = librarynode->
NextSiblingElement
()) {
if
(
strcmp
(librarynode->
Name
(),
"
importer
"
) ==
0
)
mImporters
[extension].
insert
(librarynode->
GetText
());
else
unknown_elements.
insert
(librarynode->
Name
());
}
}
else
if
(markupnodename ==
"
codeblocks
"
) {
for
(
const
tinyxml2::XMLElement *blocknode = markupnode->
FirstChildElement
(); blocknode; blocknode = blocknode->
NextSiblingElement
()) {
const
std::string blocknodename = blocknode->
Name
();
if
(blocknodename ==
"
block
"
) {
const
char
* blockName = blocknode->
Attribute
(
"
name
"
);
if
(blockName)
mExecutableBlocks
[extension].
addBlock
(blockName);
}
else
if
(blocknodename ==
"
structure
"
) {
const
char
* start = blocknode->
Attribute
(
"
start
"
);
if
(start)
mExecutableBlocks
[extension].
setStart
(start);
const
char
* end = blocknode->
Attribute
(
"
end
"
);
if
(end)
mExecutableBlocks
[extension].
setEnd
(end);
const
char
* offset = blocknode->
Attribute
(
"
offset
"
);
if
(offset)
mExecutableBlocks
[extension].
setOffset
(
atoi
(offset));
}
else
unknown_elements.
insert
(blocknodename);
}
}
else
unknown_elements.
insert
(markupnodename);
}
}
else
if
(nodename ==
"
container
"
) {
const
char
*
const
id = node->
Attribute
(
"
id
"
);
if
(!id)
return
Error
(
MISSING_ATTRIBUTE
,
"
id
"
);
Container& container = containers[id];
const
char
*
const
inherits = node->
Attribute
(
"
inherits
"
);
if
(inherits) {
const
std::map<std::string, Container>::const_iterator i = containers.
find
(inherits);
if
(i != containers.
end
())
container = i->
second
;
//
Take values from parent and overwrite them if necessary
else
return
Error
(
BAD_ATTRIBUTE_VALUE
, inherits);
}
const
char
*
const
startPattern = node->
Attribute
(
"
startPattern
"
);
if
(startPattern) {
container.
startPattern
= startPattern;
container.
startPattern2
= container.
startPattern
+
"
!!::
"
;
}
const
char
*
const
endPattern = node->
Attribute
(
"
endPattern
"
);
if
(endPattern)
container.
endPattern
= endPattern;
const
char
*
const
itEndPattern = node->
Attribute
(
"
itEndPattern
"
);
if
(itEndPattern)
container.
itEndPattern
= itEndPattern;
const
char
*
const
opLessAllowed = node->
Attribute
(
"
opLessAllowed
"
);
if
(opLessAllowed)
container.
opLessAllowed
=
std::string
(opLessAllowed) ==
"
true
"
;
const
char
*
const
hasInitializerListConstructor = node->
Attribute
(
"
hasInitializerListConstructor
"
);
if
(hasInitializerListConstructor)
container.
hasInitializerListConstructor
=
std::string
(hasInitializerListConstructor) ==
"
true
"
;
for
(
const
tinyxml2::XMLElement *containerNode = node->
FirstChildElement
(); containerNode; containerNode = containerNode->
NextSiblingElement
()) {
const
std::string containerNodeName = containerNode->
Name
();
if
(containerNodeName ==
"
size
"
|| containerNodeName ==
"
access
"
|| containerNodeName ==
"
other
"
) {
for
(
const
tinyxml2::XMLElement *functionNode = containerNode->
FirstChildElement
(); functionNode; functionNode = functionNode->
NextSiblingElement
()) {
if
(
std::string
(functionNode->
Name
()) !=
"
function
"
) {
unknown_elements.
insert
(functionNode->
Name
());
continue
;
}
const
char
*
const
functionName = functionNode->
Attribute
(
"
name
"
);
if
(!functionName)
return
Error
(
MISSING_ATTRIBUTE
,
"
name
"
);
const
char
*
const
action_ptr = functionNode->
Attribute
(
"
action
"
);
Container::Action action = Container::Action::
NO_ACTION
;
if
(action_ptr) {
std::string actionName = action_ptr;
if
(actionName ==
"
resize
"
)
action = Container::Action::
RESIZE
;
else
if
(actionName ==
"
clear
"
)
action = Container::Action::
CLEAR
;
else
if
(actionName ==
"
push
"
)
action = Container::Action::
PUSH
;
else
if
(actionName ==
"
pop
"
)
action = Container::Action::
POP
;
else
if
(actionName ==
"
find
"
)
action = Container::Action::
FIND
;
else
if
(actionName ==
"
insert
"
)
action = Container::Action::
INSERT
;
else
if
(actionName ==
"
erase
"
)
action = Container::Action::
ERASE
;
else
if
(actionName ==
"
change-content
"
)
action = Container::Action::
CHANGE_CONTENT
;
else
if
(actionName ==
"
change-internal
"
)
action = Container::Action::
CHANGE_INTERNAL
;
else
if
(actionName ==
"
change
"
)
action = Container::Action::
CHANGE
;
else
return
Error
(
BAD_ATTRIBUTE_VALUE
, actionName);
}
const
char
*
const
yield_ptr = functionNode->
Attribute
(
"
yields
"
);
Container::Yield yield = Container::Yield::
NO_YIELD
;
if
(yield_ptr) {
std::string yieldName = yield_ptr;
if
(yieldName ==
"
at_index
"
)
yield = Container::Yield::
AT_INDEX
;
else
if
(yieldName ==
"
item
"
)
yield = Container::Yield::
ITEM
;
else
if
(yieldName ==
"
buffer
"
)
yield = Container::Yield::
BUFFER
;
else
if
(yieldName ==
"
buffer-nt
"
)
yield = Container::Yield::
BUFFER_NT
;
else
if
(yieldName ==
"
start-iterator
"
)
yield = Container::Yield::
START_ITERATOR
;
else
if
(yieldName ==
"
end-iterator
"
)
yield = Container::Yield::
END_ITERATOR
;
else
if
(yieldName ==
"
iterator
"
)
yield = Container::Yield::
ITERATOR
;
else
if
(yieldName ==
"
size
"
)
yield = Container::Yield::
SIZE
;
else
if
(yieldName ==
"
empty
"
)
yield = Container::Yield::
EMPTY
;
else
return
Error
(
BAD_ATTRIBUTE_VALUE
, yieldName);
}
container.
functions
[functionName].
action
= action;
container.
functions
[functionName].
yield
= yield;
}
if
(containerNodeName ==
"
size
"
) {
const
char
*
const
templateArg = containerNode->
Attribute
(
"
templateParameter
"
);
if
(templateArg)
container.
size_templateArgNo
=
atoi
(templateArg);
}
else
if
(containerNodeName ==
"
access
"
) {
const
char
*
const
indexArg = containerNode->
Attribute
(
"
indexOperator
"
);
if
(indexArg)
container.
arrayLike_indexOp
=
std::string
(indexArg) ==
"
array-like
"
;
}
}
else
if
(containerNodeName ==
"
type
"
) {
const
char
*
const
templateArg = containerNode->
Attribute
(
"
templateParameter
"
);
if
(templateArg)
container.
type_templateArgNo
=
atoi
(templateArg);
const
char
*
const
string = containerNode->
Attribute
(
"
string
"
);
if
(string)
container.
stdStringLike
=
std::string
(string) ==
"
std-like
"
;
const
char
*
const
associative = containerNode->
Attribute
(
"
associative
"
);
if
(associative)
container.
stdAssociativeLike
=
std::string
(associative) ==
"
std-like
"
;
}
else
unknown_elements.
insert
(containerNodeName);
}
}
else
if
(nodename ==
"
smart-pointer
"
) {
const
char
*className = node->
Attribute
(
"
class-name
"
);
if
(className)
smartPointers.
insert
(className);
}
else
if
(nodename ==
"
type-checks
"
) {
for
(
const
tinyxml2::XMLElement *checkNode = node->
FirstChildElement
(); checkNode; checkNode = checkNode->
NextSiblingElement
()) {
const
std::string &checkName = checkNode->
Name
();
for
(
const
tinyxml2::XMLElement *checkTypeNode = checkNode->
FirstChildElement
(); checkTypeNode; checkTypeNode = checkTypeNode->
NextSiblingElement
()) {
const
std::string checkTypeName = checkTypeNode->
Name
();
const
char
*typeName = checkTypeNode->
GetText
();
if
(!typeName)
continue
;
if
(checkTypeName ==
"
check
"
)
mTypeChecks
[std::pair<std::string,std::string>(checkName, typeName)] = TypeCheck::check;
else
if
(checkTypeName ==
"
suppress
"
)
mTypeChecks
[std::pair<std::string,std::string>(checkName, typeName)] = TypeCheck::suppress;
}
}
}
else
if
(nodename ==
"
podtype
"
) {
const
char
*
const
name = node->
Attribute
(
"
name
"
);
if
(!name)
return
Error
(
MISSING_ATTRIBUTE
,
"
name
"
);
PodType podType = {
0
};
podType.
stdtype
= PodType::
NO
;
const
char
*
const
stdtype = node->
Attribute
(
"
stdtype
"
);
if
(stdtype) {
if
(
std::strcmp
(stdtype,
"
bool
"
) ==
0
)
podType.
stdtype
= PodType::
BOOL
;
else
if
(
std::strcmp
(stdtype,
"
char
"
) ==
0
)
podType.
stdtype
= PodType::
CHAR
;
else
if
(
std::strcmp
(stdtype,
"
short
"
) ==
0
)
podType.
stdtype
= PodType::
SHORT
;
else
if
(
std::strcmp
(stdtype,
"
int
"
) ==
0
)
podType.
stdtype
= PodType::
INT
;
else
if
(
std::strcmp
(stdtype,
"
long
"
) ==
0
)
podType.
stdtype
= PodType::
LONG
;
else
if
(
std::strcmp
(stdtype,
"
long long
"
) ==
0
)
podType.
stdtype
= PodType::
LONGLONG
;
}
const
char
*
const
size = node->
Attribute
(
"
size
"
);
if
(size)
podType.
size
=
atoi
(size);
const
char
*
const
sign = node->
Attribute
(
"
sign
"
);
if
(sign)
podType.
sign
= *sign;
for
(
const
std::string &s :
getnames
(name))
mPodTypes
[s] = podType;
}
else
if
(nodename ==
"
platformtype
"
) {
const
char
*
const
type_name = node->
Attribute
(
"
name
"
);
if
(type_name ==
nullptr
)
return
Error
(
MISSING_ATTRIBUTE
,
"
name
"
);
const
char
*value = node->
Attribute
(
"
value
"
);
if
(value ==
nullptr
)
return
Error
(
MISSING_ATTRIBUTE
,
"
value
"
);
PlatformType type;
type.
mType
= value;
std::set<std::string> platform;
for
(
const
tinyxml2::XMLElement *typenode = node->
FirstChildElement
(); typenode; typenode = typenode->
NextSiblingElement
()) {
const
std::string typenodename = typenode->
Name
();
if
(typenodename ==
"
platform
"
) {
const
char
*
const
type_attribute = typenode->
Attribute
(
"
type
"
);
if
(type_attribute ==
nullptr
)
return
Error
(
MISSING_ATTRIBUTE
,
"
type
"
);
platform.
insert
(type_attribute);
}
else
if
(typenodename ==
"
signed
"
)
type.
mSigned
=
true
;
else
if
(typenodename ==
"
unsigned
"
)
type.
mUnsigned
=
true
;
else
if
(typenodename ==
"
long
"
)
type.
mLong
=
true
;
else
if
(typenodename ==
"
pointer
"
)
type.
mPointer
=
true
;
else
if
(typenodename ==
"
ptr_ptr
"
)
type.
mPtrPtr
=
true
;
else
if
(typenodename ==
"
const_ptr
"
)
type.
mConstPtr
=
true
;
else
unknown_elements.
insert
(typenodename);
}
if
(platform.
empty
()) {
const
PlatformType *
const
type_ptr =
platform_type
(type_name, emptyString);
if
(type_ptr) {
if
(*type_ptr == type)
return
Error
(
DUPLICATE_PLATFORM_TYPE
, type_name);
return
Error
(
PLATFORM_TYPE_REDEFINED
, type_name);
}
mPlatformTypes
[type_name] = type;
}
else
{
for
(
const
std::string &p : platform) {
const
PlatformType *
const
type_ptr =
platform_type
(type_name, p);
if
(type_ptr) {
if
(*type_ptr == type)
return
Error
(
DUPLICATE_PLATFORM_TYPE
, type_name);
return
Error
(
PLATFORM_TYPE_REDEFINED
, type_name);
}
mPlatforms
[p].
mPlatformTypes
[type_name] = type;
}
}
}
else
unknown_elements.
insert
(nodename);
}
if
(!unknown_elements.
empty
()) {
std::string str;
for
(std::set<std::string>::const_iterator i = unknown_elements.
begin
(); i != unknown_elements.
end
();) {
str += *i;
if
(++i != unknown_elements.
end
())
str +=
"
,
"
;
}
return
Error
(
UNKNOWN_ELEMENT
, str);
}
return
Error
(
OK
);
}
Library::Error
Library::loadFunction
(
const
tinyxml2::XMLElement *
const
node,
const
std::string &name, std::set<std::string> &unknown_elements)
{
if
(name.
empty
())
return
Error
(
OK
);
Function& func = functions[name];
for
(
const
tinyxml2::XMLElement *functionnode = node->
FirstChildElement
(); functionnode; functionnode = functionnode->
NextSiblingElement
()) {
const
std::string functionnodename = functionnode->
Name
();
if
(functionnodename ==
"
noreturn
"
)
mNoReturn
[name] = (
strcmp
(functionnode->
GetText
(),
"
true
"
) ==
0
);
else
if
(functionnodename ==
"
pure
"
)
func.
ispure
=
true
;
else
if
(functionnodename ==
"
const
"
) {
func.
ispure
=
true
;
func.
isconst
=
true
;
//
a constant function is pure
}
else
if
(functionnodename ==
"
leak-ignore
"
)
func.
leakignore
=
true
;
else
if
(functionnodename ==
"
use-retval
"
)
func.
useretval
=
true
;
else
if
(functionnodename ==
"
returnValue
"
) {
if
(
const
char
*expr = functionnode->
GetText
())
mReturnValue
[name] = expr;
if
(
const
char
*type = functionnode->
Attribute
(
"
type
"
))
mReturnValueType
[name] = type;
if
(
const
char
*container = functionnode->
Attribute
(
"
container
"
))
mReturnValueContainer
[name] =
std::atoi
(container);
if
(
const
char
*unknownReturnValues = functionnode->
Attribute
(
"
unknownValues
"
)) {
if
(
std::strcmp
(unknownReturnValues,
"
all
"
) ==
0
) {
std::vector<MathLib::bigint> values{
LLONG_MIN
,
LLONG_MAX
};
mUnknownReturnValues
[name] = values;
}
}
}
else
if
(functionnodename ==
"
arg
"
) {
const
char
* argNrString = functionnode->
Attribute
(
"
nr
"
);
if
(!argNrString)
return
Error
(
MISSING_ATTRIBUTE
,
"
nr
"
);
const
bool
bAnyArg =
strcmp
(argNrString,
"
any
"
) ==
0
;
const
bool
bVariadicArg =
strcmp
(argNrString,
"
variadic
"
) ==
0
;
const
int
nr = (bAnyArg || bVariadicArg) ? -
1
:
std::atoi
(argNrString);
ArgumentChecks &ac = func.
argumentChecks
[nr];
ac.
optional
= functionnode->
Attribute
(
"
default
"
) !=
nullptr
;
ac.
variadic
= bVariadicArg;
const
char
*
const
argDirection = functionnode->
Attribute
(
"
direction
"
);
if
(argDirection) {
const
size_t
argDirLen =
strlen
(argDirection);
if
(!
strncmp
(argDirection,
"
in
"
, argDirLen)) {
ac.
direction
= ArgumentChecks::Direction::
DIR_IN
;
}
else
if
(!
strncmp
(argDirection,
"
out
"
, argDirLen)) {
ac.
direction
= ArgumentChecks::Direction::
DIR_OUT
;
}
else
if
(!
strncmp
(argDirection,
"
inout
"
, argDirLen)) {
ac.
direction
= ArgumentChecks::Direction::
DIR_INOUT
;
}
}
for
(
const
tinyxml2::XMLElement *argnode = functionnode->
FirstChildElement
(); argnode; argnode = argnode->
NextSiblingElement
()) {
const
std::string argnodename = argnode->
Name
();
int
indirect =
0
;
const
char
*
const
indirectStr = node->
Attribute
(
"
indirect
"
);
if
(indirectStr)
indirect =
atoi
(indirectStr);
if
(argnodename ==
"
not-bool
"
)
ac.
notbool
=
true
;
else
if
(argnodename ==
"
not-null
"
)
ac.
notnull
=
true
;
else
if
(argnodename ==
"
not-uninit
"
)
ac.
notuninit
= indirect;
else
if
(argnodename ==
"
formatstr
"
)
ac.
formatstr
=
true
;
else
if
(argnodename ==
"
strz
"
)
ac.
strz
=
true
;
else
if
(argnodename ==
"
valid
"
) {
//
Validate the validation expression
const
char
*p = argnode->
GetText
();
bool
error =
false
;
bool
range =
false
;
bool
has_dot =
false
;
if
(!p)
return
Error
(
BAD_ATTRIBUTE_VALUE
,
"
\"\"
"
);
error = *p ==
'
.
'
;
for
(; *p; p++) {
if
(
std::isdigit
(*p))
error |= (*(p+
1
) ==
'
-
'
);
else
if
(*p ==
'
:
'
) {
error |= range | (*(p+
1
) ==
'
.
'
);
range =
true
;
has_dot =
false
;
}
else
if
(*p ==
'
-
'
)
error |= (!
std::isdigit
(*(p+
1
)));
else
if
(*p ==
'
,
'
) {
range =
false
;
error |= *(p+
1
) ==
'
.
'
;
has_dot =
false
;
}
else
if
(*p ==
'
.
'
) {
error |= has_dot | (!
std::isdigit
(*(p+
1
)));
has_dot =
true
;
}
else
error =
true
;
}
if
(error)
return
Error
(
BAD_ATTRIBUTE_VALUE
, argnode->
GetText
());
//
Set validation expression
ac.
valid
= argnode->
GetText
();
}
else
if
(argnodename ==
"
minsize
"
) {
const
char
*typeattr = argnode->
Attribute
(
"
type
"
);
if
(!typeattr)
return
Error
(
MISSING_ATTRIBUTE
,
"
type
"
);
ArgumentChecks::MinSize::Type type;
if
(
strcmp
(typeattr,
"
strlen
"
)==
0
)
type = ArgumentChecks::MinSize::Type::
STRLEN
;
else
if
(
strcmp
(typeattr,
"
argvalue
"
)==
0
)
type = ArgumentChecks::MinSize::Type::
ARGVALUE
;
else
if
(
strcmp
(typeattr,
"
sizeof
"
)==
0
)
type = ArgumentChecks::MinSize::Type::
SIZEOF
;
else
if
(
strcmp
(typeattr,
"
mul
"
)==
0
)
type = ArgumentChecks::MinSize::Type::
MUL
;
else
if
(
strcmp
(typeattr,
"
value
"
)==
0
)
type = ArgumentChecks::MinSize::Type::
VALUE
;
else
return
Error
(
BAD_ATTRIBUTE_VALUE
, typeattr);
if
(type == ArgumentChecks::MinSize::Type::
VALUE
) {
const
char
*valueattr = argnode->
Attribute
(
"
value
"
);
if
(!valueattr)
return
Error
(
MISSING_ATTRIBUTE
,
"
value
"
);
long
long
minsizevalue =
0
;
try
{
minsizevalue =
MathLib::toLongNumber
(valueattr);
}
catch
(
const
InternalError&) {
return
Error
(
BAD_ATTRIBUTE_VALUE
, valueattr);
}
if
(minsizevalue <=
0
)
return
Error
(
BAD_ATTRIBUTE_VALUE
, valueattr);
ac.
minsizes
.
emplace_back
(type,
0
);
ac.
minsizes
.
back
().
value
= minsizevalue;
}
else
{
const
char
*argattr = argnode->
Attribute
(
"
arg
"
);
if
(!argattr)
return
Error
(
MISSING_ATTRIBUTE
,
"
arg
"
);
if
(
strlen
(argattr) !=
1
|| argattr[
0
]<
'
0
'
|| argattr[
0
]>
'
9
'
)
return
Error
(
BAD_ATTRIBUTE_VALUE
, argattr);
ac.
minsizes
.
reserve
(type == ArgumentChecks::MinSize::Type::
MUL
?
2
:
1
);
ac.
minsizes
.
emplace_back
(type, argattr[
0
] -
'
0
'
);
if
(type == ArgumentChecks::MinSize::Type::
MUL
) {
const
char
*arg2attr = argnode->
Attribute
(
"
arg2
"
);
if
(!arg2attr)
return
Error
(
MISSING_ATTRIBUTE
,
"
arg2
"
);
if
(
strlen
(arg2attr) !=
1
|| arg2attr[
0
]<
'
0
'
|| arg2attr[
0
]>
'
9
'
)
return
Error
(
BAD_ATTRIBUTE_VALUE
, arg2attr);
ac.
minsizes
.
back
().
arg2
= arg2attr[
0
] -
'
0
'
;
}
}
}
else
if
(argnodename ==
"
iterator
"
) {
ac.
iteratorInfo
.
it
=
true
;
const
char
* str = argnode->
Attribute
(
"
type
"
);
ac.
iteratorInfo
.
first
= str ? (
std::strcmp
(str,
"
first
"
) ==
0
) :
false
;
ac.
iteratorInfo
.
last
= str ? (
std::strcmp
(str,
"
last
"
) ==
0
) :
false
;
str = argnode->
Attribute
(
"
container
"
);
ac.
iteratorInfo
.
container
= str ?
std::atoi
(str) :
0
;
}
else
unknown_elements.
insert
(argnodename);
}
if
(ac.
notuninit
==
0
)
ac.
notuninit
= ac.
notnull
?
1
:
0
;
}
else
if
(functionnodename ==
"
ignorefunction
"
) {
func.
ignore
=
true
;
}
else
if
(functionnodename ==
"
formatstr
"
) {
func.
formatstr
=
true
;
const
tinyxml2::XMLAttribute* scan = functionnode->
FindAttribute
(
"
scan
"
);
const
tinyxml2::XMLAttribute* secure = functionnode->
FindAttribute
(
"
secure
"
);
func.
formatstr_scan
= scan && scan->
BoolValue
();
func.
formatstr_secure
= secure && secure->
BoolValue
();
}
else
if
(functionnodename ==
"
warn
"
) {
WarnInfo wi;
const
char
*
const
severity = functionnode->
Attribute
(
"
severity
"
);
if
(severity ==
nullptr
)
return
Error
(
MISSING_ATTRIBUTE
,
"
severity
"
);
wi.
severity
=
Severity::fromString
(severity);
const
char
*
const
cstd = functionnode->
Attribute
(
"
cstd
"
);
if
(cstd) {
if
(!wi.
standards
.
setC
(cstd))
return
Error
(
BAD_ATTRIBUTE_VALUE
, cstd);
}
else
wi.
standards
.
c
= Standards::
C89
;
const
char
*
const
cppstd = functionnode->
Attribute
(
"
cppstd
"
);
if
(cppstd) {
if
(!wi.
standards
.
setCPP
(cppstd))
return
Error
(
BAD_ATTRIBUTE_VALUE
, cppstd);
}
else
wi.
standards
.
cpp
= Standards::
CPP03
;
const
char
*
const
reason = functionnode->
Attribute
(
"
reason
"
);
const
char
*
const
alternatives = functionnode->
Attribute
(
"
alternatives
"
);
if
(reason && alternatives) {
//
Construct message
wi.
message
=
std::string
(reason) +
"
function '
"
+ name +
"
' called. It is recommended to use
"
;
std::vector<std::string> alt =
getnames
(alternatives);
for
(std::
size_t
i =
0
; i < alt.
size
(); ++i) {
wi.
message
+=
"
'
"
+ alt[i] +
"
'
"
;
if
(i == alt.
size
() -
1
)
wi.
message
+=
"
instead.
"
;
else
if
(i == alt.
size
() -
2
)
wi.
message
+=
"
or
"
;
else
wi.
message
+=
"
,
"
;
}
}
else
{
const
char
*
const
message = functionnode->
GetText
();
if
(!message) {
return
Error
(
MISSING_ATTRIBUTE
,
"
\"
reason
\"
and
\"
alternatives
\"
or some text.
"
);
}
else
wi.
message
= message;
}
functionwarn[name] = wi;
}
else
unknown_elements.
insert
(functionnodename);
}
return
Error
(
OK
);
}
std::vector<Library::InvalidArgValue>
Library::getInvalidArgValues
(
const
std::string &validExpr)
{
std::vector<Library::InvalidArgValue> valid;
TokenList
tokenList
(
nullptr
);
gettokenlistfromvalid
(validExpr, tokenList);
for
(
const
Token *tok = tokenList.
front
(); tok; tok = tok ? tok->
next
() :
nullptr
) {
if
(tok->
str
() ==
"
,
"
)
continue
;
if
(
Token::Match
(tok,
"
: %num%
"
)) {
valid.
push_back
(InvalidArgValue{InvalidArgValue::le, tok->
next
()->
str
(),
std::string
()});
tok = tok->
tokAt
(
2
);
}
else
if
(
Token::Match
(tok,
"
%num% : %num%
"
)) {
valid.
push_back
(InvalidArgValue{InvalidArgValue::range, tok->
str
(), tok->
strAt
(
2
)});
tok = tok->
tokAt
(
3
);
}
else
if
(
Token::Match
(tok,
"
%num% :
"
)) {
valid.
push_back
(InvalidArgValue{InvalidArgValue::ge, tok->
str
(),
std::string
()});
tok = tok->
tokAt
(
2
);
}
else
if
(
Token::Match
(tok,
"
%num%
"
)) {
valid.
push_back
(InvalidArgValue{InvalidArgValue::eq, tok->
str
(),
std::string
()});
tok = tok->
next
();
}
}
std::vector<Library::InvalidArgValue> invalid;
if
(valid.
empty
())
return
invalid;
if
(valid[
0
].
type
== InvalidArgValue::ge || valid[
0
].
type
== InvalidArgValue::eq)
invalid.
push_back
(InvalidArgValue{InvalidArgValue::lt, valid[
0
].
op1
,
std::string
()});
if
(valid.
back
().
type
== InvalidArgValue::le || valid.
back
().
type
== InvalidArgValue::eq)
invalid.
push_back
(InvalidArgValue{InvalidArgValue::gt, valid[
0
].
op1
,
std::string
()});
for
(
int
i =
0
; i +
1
< valid.
size
(); i++) {
const
InvalidArgValue &v1 = valid[i];
const
InvalidArgValue &v2 = valid[i +
1
];
if
(v1.
type
== InvalidArgValue::le && v2.
type
== InvalidArgValue::ge) {
if
(v1.
isInt
()) {
MathLib::bigint op1 =
MathLib::toLongNumber
(v1.
op1
);
MathLib::bigint op2 =
MathLib::toLongNumber
(v2.
op1
);
if
(op1 +
1
== op2 -
1
)
invalid.
push_back
(InvalidArgValue{InvalidArgValue::eq,
MathLib::toString
(op1 +
1
),
std::string
()});
else
invalid.
push_back
(InvalidArgValue{InvalidArgValue::range,
MathLib::toString
(op1 +
1
),
MathLib::toString
(op2 -
1
)});
}
}
}
return
invalid;
}
bool
Library::isIntArgValid
(
const
Token *ftok,
int
argnr,
const
MathLib::bigint argvalue)
const
{
const
ArgumentChecks *ac =
getarg
(ftok, argnr);
if
(!ac || ac->
valid
.
empty
())
return
true
;
else
if
(ac->
valid
.
find
(
'
.
'
) != std::string::npos)
return
isFloatArgValid
(ftok, argnr, argvalue);
TokenList
tokenList
(
nullptr
);
gettokenlistfromvalid
(ac->
valid
, tokenList);
for
(
const
Token *tok = tokenList.
front
(); tok; tok = tok->
next
()) {
if
(tok->
isNumber
() && argvalue ==
MathLib::toLongNumber
(tok->
str
()))
return
true
;
if
(
Token::Match
(tok,
"
%num% : %num%
"
) && argvalue >=
MathLib::toLongNumber
(tok->
str
()) && argvalue <=
MathLib::toLongNumber
(tok->
strAt
(
2
)))
return
true
;
if
(
Token::Match
(tok,
"
%num% : ,
"
) && argvalue >=
MathLib::toLongNumber
(tok->
str
()))
return
true
;
if
((!tok->
previous
() || tok->
previous
()->
str
() ==
"
,
"
) &&
Token::Match
(tok,
"
: %num%
"
) && argvalue <=
MathLib::toLongNumber
(tok->
strAt
(
1
)))
return
true
;
}
return
false
;
}
bool
Library::isFloatArgValid
(
const
Token *ftok,
int
argnr,
double
argvalue)
const
{
const
ArgumentChecks *ac =
getarg
(ftok, argnr);
if
(!ac || ac->
valid
.
empty
())
return
true
;
TokenList
tokenList
(
nullptr
);
gettokenlistfromvalid
(ac->
valid
, tokenList);
for
(
const
Token *tok = tokenList.
front
(); tok; tok = tok->
next
()) {
if
(
Token::Match
(tok,
"
%num% : %num%
"
) && argvalue >=
MathLib::toDoubleNumber
(tok->
str
()) && argvalue <=
MathLib::toDoubleNumber
(tok->
strAt
(
2
)))
return
true
;
if
(
Token::Match
(tok,
"
%num% : ,
"
) && argvalue >=
MathLib::toDoubleNumber
(tok->
str
()))
return
true
;
if
((!tok->
previous
() || tok->
previous
()->
str
() ==
"
,
"
) &&
Token::Match
(tok,
"
: %num%
"
) && argvalue <=
MathLib::toDoubleNumber
(tok->
strAt
(
1
)))
return
true
;
}
return
false
;
}
std::string
Library::getFunctionName
(
const
Token *ftok,
bool
*error)
const
{
if
(!ftok) {
*error =
true
;
return
"
"
;
}
if
(ftok->
isName
()) {
for
(
const
Scope *scope = ftok->
scope
(); scope; scope = scope->
nestedIn
) {
if
(!scope->
isClassOrStruct
())
continue
;
const
std::vector<Type::BaseInfo> &derivedFrom = scope->
definedType
->
derivedFrom
;
for
(
const
Type::BaseInfo & baseInfo : derivedFrom) {
const
std::string
name
(baseInfo.
name
+
"
::
"
+ ftok->
str
());
if
(functions.
find
(name) != functions.
end
() &&
matchArguments
(ftok, name))
return
name;
}
}
return
ftok->
str
();
}
if
(ftok->
str
() ==
"
::
"
) {
if
(!ftok->
astOperand2
())
return
getFunctionName
(ftok->
astOperand1
(), error);
return
getFunctionName
(ftok->
astOperand1
(),error) +
"
::
"
+
getFunctionName
(ftok->
astOperand2
(),error);
}
if
(ftok->
str
() ==
"
.
"
&& ftok->
astOperand1
()) {
const
std::string type =
astCanonicalType
(ftok->
astOperand1
());
if
(type.
empty
()) {
*error =
true
;
return
"
"
;
}
return
type +
"
::
"
+
getFunctionName
(ftok->
astOperand2
(),error);
}
*error =
true
;
return
"
"
;
}
std::string
Library::getFunctionName
(
const
Token *ftok)
const
{
if
(!
Token::Match
(ftok,
"
%name% (
"
) && (ftok->
strAt
(-
1
) !=
"
&
"
|| ftok->
previous
()->
astOperand2
()))
return
"
"
;
//
Lookup function name using AST..
if
(ftok->
astParent
()) {
bool
error =
false
;
const
Token * tok = ftok->
astParent
()->
isUnaryOp
(
"
&
"
) ? ftok->
astParent
()->
astOperand1
() : ftok->
next
()->
astOperand1
();
const
std::string ret =
getFunctionName
(tok, &error);
return
error ?
std::string
() : ret;
}
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL