-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdbjson.hpp
1881 lines (1718 loc) · 69.9 KB
/
dbjson.hpp
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
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wpessimizing-move"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"
#include "clang/AST/CommentVisitor.h"
#include "clang/AST/Comment.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/AST/Type.h"
#include "clang/Tooling/Syntax/Tokens.h"
using namespace clang;
#include "utils.h"
#include "sha.h"
#include "base64.h"
#include "printers.h"
#include "MacroHandler.h"
#include <stdint.h>
#include <string>
#include <algorithm>
#include <sstream>
#include <vector>
#include <stack>
#include <fstream>
#include <streambuf>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#define DBG(on,...) do { if (on) { __VA_ARGS__; } } while(0)
#define DEBUG_TYPESTRING 0
#define DEBUG_HASH 0
extern thread_local size_t exprOrd;
struct anonRecord {
std::vector<std::string> fieldNames;
std::string hash;
};
static std::string JSONReplacementToken = "\"\"\"$\"\"\"";
static std::string ORDReplacementToken = "\"\"\"@\"\"\"";
static std::string ARGeplacementToken = "\"\"\"&\"\"\"";
class DbJSONClassVisitor
: public RecursiveASTVisitor<DbJSONClassVisitor> {
using Base = RecursiveASTVisitor<DbJSONClassVisitor>;
public:
explicit DbJSONClassVisitor(ASTContext &Context)
: TypeNum(0), VarNum(0), FuncNum(0), lastFunctionDef(0), CTA(0), missingRefsCount(0), Context(Context) {}
bool shouldVisitImplicitCode() const {return true;}
static QualType getDeclType(Decl* D) {
if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
return TDD->getUnderlyingType();
if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
return VD->getType();
return QualType();
}
static QualType GetBaseType(QualType T) {
// FIXME: This should be on the Type class!
QualType BaseType = T;
while (!BaseType->isSpecifierType()) {
if (isa<TypedefType>(BaseType))
break;
else if (const PointerType* PTy = BaseType->getAs<PointerType>())
BaseType = PTy->getPointeeType();
else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
BaseType = BPy->getPointeeType();
else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
BaseType = ATy->getElementType();
else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
BaseType = FTy->getReturnType();
else if (const VectorType *VTy = BaseType->getAs<VectorType>())
BaseType = VTy->getElementType();
else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
BaseType = RTy->getPointeeType();
else if (const AutoType *ATy = BaseType->getAs<AutoType>())
BaseType = ATy->getDeducedType();
else if (const AttributedType *AtrTy = BaseType->getAs<AttributedType>())
BaseType = AtrTy->getModifiedType();
COMPAT_VERSION_GE(15,
else if (const BTFTagAttributedType *AtrTy = BaseType->getAs<BTFTagAttributedType>())
BaseType = AtrTy->getWrappedType();
)
else if (const ParenType *PTy = BaseType->getAs<ParenType>())
BaseType = PTy->desugar();
else
break;
}
return BaseType;
}
struct ValueHolder {
const ValueDecl* value;
unsigned pos;
ValueHolder(const ValueDecl* value, unsigned pos): value(value), pos(pos) {}
const ValueDecl* getValue() { return value; }
unsigned getPos() { return pos; }
const ValueDecl* getValue() const { return value; }
unsigned getPos() const { return pos; }
bool operator<(ValueHolder other) const {
if (value<other.value) return true;
if (value>other.value) return false;
return pos<other.pos;
}
bool operator==(ValueHolder other) const {
return (value==other.value) && (pos==other.pos);
}
};
struct LiteralHolder {
enum LiteralType {
LiteralString,
LiteralInteger,
LiteralChar,
LiteralFloat,
} type;
struct PrivLiterals {
std::string stringLiteral;
llvm::APSInt integerLiteral;
unsigned int charLiteral;
double floatingLiteral;
} prvLiteral;
unsigned pos;
bool literalLower(const LiteralHolder &other) const {
if (type < other.type) return true;
if (type > other.type) return false;
if (type==LiteralString) {
return prvLiteral.stringLiteral.compare(other.prvLiteral.stringLiteral)<0;
}
if (type==LiteralInteger) {
return prvLiteral.integerLiteral.extOrTrunc(63).getExtValue() < other.prvLiteral.integerLiteral.extOrTrunc(63).getExtValue();
}
if (type==LiteralChar) {
return prvLiteral.charLiteral < other.prvLiteral.charLiteral;
}
if (type==LiteralFloat) {
return prvLiteral.floatingLiteral < other.prvLiteral.floatingLiteral;
}
assert( 0 && "Wrong literal type.");
}
bool operator<(const LiteralHolder &other) const {
return literalLower(other);
}
};
typedef std::vector<std::string> recordFields_t;
typedef std::vector<size_t> recordOffsets_t;
typedef std::pair<recordFields_t,recordOffsets_t> recordInfo_t;
class ObjectID{
size_t _id = 0;
bool is_set = false;
public:
ObjectID(){}
void setID(size_t id){_id = id;}
void setIDProper(size_t id){_id = id; is_set = true;}
operator size_t(){
assert(is_set);
return _id;
}
};
struct TypeData{
ObjectID id;
QualType T;
size_t size;
recordInfo_t *RInfo;
std::string hash;
std::shared_ptr<std::string> output;
void *usedrefs;
};
typedef std::map<QualType,TypeData> TypeArray_t;
TypeArray_t TypeMap;
size_t TypeNum;
size_t getTypeNum() {
return TypeNum;
}
// use only when iterating over all types
// unsafe with types obtained from clang api
TypeArray_t& getTypeMap() {
return TypeMap;
}
TypeData& getTypeData(QualType T) {
T = typeForMap(T);
if (TypeMap.find(T)==TypeMap.end()) {
llvm::outs()<<"Type not in map:"<<T.getAsOpaquePtr()<<'\n';
T.dump();
assert(0);
}
return TypeMap.at(T);
}
struct FopsObject{
const QualType T;
const VarDecl *V;
const FunctionDecl *F;
enum FopsKind{
FObjGlobal,
FObjLocal,
FObjFunction,
} kind;
std::string FopsKindName() const {
switch(kind){
case FObjGlobal:
return "global";
case FObjLocal:
return "local";
case FObjFunction:
return "function";
default:
assert(0 && "Invalid Fops kind");
}
}
FopsObject(QualType Type, const VarDecl *Var, const FunctionDecl *Func = nullptr) : T(Type), V(Var), F(Func) {
if(!Var){
// fallback case without associated variable
kind = FObjFunction;
}
else{
if(Var->isDefinedOutsideFunctionOrMethod()){
// global
kind = FObjGlobal;
}
else{
// local
kind = FObjLocal;
}
}
}
bool operator<(const FopsObject &other) const {
if(kind != other.kind){
return kind < other.kind;
}
else if(T != other.T){
return T <other.T;
}
else if(V){
return V <other.V;
}
else{
return F <other.F;
}
}
operator bool() const {
return bool(kind);
}
};
struct FopsData{
FopsData(FopsObject &FObj) : obj(FObj) {}
FopsObject obj;
std::string hash;
size_t type_id;
size_t var_id;
size_t func_id;
std::string loc;
std::map <size_t,std::set<const FunctionDecl*>> fops_info; //member_id : function id
std::shared_ptr<std::string>output;
bool operator<(const FopsData &other) const {
return obj <other.obj;
}
};
typedef std::map<FopsObject,FopsData> FopsArray_t;
FopsArray_t FopsMap;
FopsArray_t &getFopsMap(){
return FopsMap;
}
typedef std::pair<int64_t,std::string> caseenum_t;
typedef std::tuple<caseenum_t,std::string,std::string,int64_t> caseinfo_t;
struct CastExprOrType {
enum CastExprOrTypeKind {
CastExprOrTypeKindCast,
CastExprOrTypeKindType,
};
CastExprOrType(CastExpr* cast): cast(cast), kind(CastExprOrTypeKindCast) {}
CastExprOrType(QualType type): type(type), kind(CastExprOrTypeKindType) {}
CastExpr* cast;
QualType type;
CastExprOrTypeKind kind;
CastExprOrTypeKind getKind() {
return kind;
}
CastExpr* getCast() {
return cast;
}
QualType getType() {
return type;
}
QualType getFinalType() {
if (kind==CastExprOrTypeKindCast) {
return cast->getType();
}
else {
return type;
}
}
bool operator <(const CastExprOrType & otherCT) const {
if (kind==CastExprOrTypeKindCast) {
return cast<otherCT.cast;
}
else {
return type<otherCT.type;
}
}
bool operator==(const CastExprOrType & otherCT) const {
if (kind==CastExprOrTypeKindCast) {
return cast==otherCT.cast;
}
else {
return type==otherCT.type;
}
}
};
struct CStyleCastOrType {
enum CStyleCastOrTypeKind {
CStyleCastOrTypeKindNone,
CStyleCastOrTypeKindCast,
CStyleCastOrTypeKindType,
};
CStyleCastExpr* CSCE;
QualType T;
CStyleCastOrTypeKind kind;
CStyleCastOrType(): CSCE(0), T(), kind(CStyleCastOrTypeKindNone) {}
CStyleCastOrType(CStyleCastExpr* CSCE): CSCE(CSCE), T(), kind(CStyleCastOrTypeKindCast) {}
CStyleCastOrType(QualType T): CSCE(0), T(T), kind(CStyleCastOrTypeKindType) {}
bool isValid() {
return kind!=CStyleCastOrTypeKindNone;
}
bool isType() {
return kind==CStyleCastOrTypeKindType;
}
bool isCast() {
return kind==CStyleCastOrTypeKindCast;
}
void setType(QualType _T) {
CSCE = 0;
T = _T;
kind = CStyleCastOrTypeKindType;
}
void setCast(CStyleCastExpr* _cast) {
CSCE = _cast;
T = QualType();
kind = CStyleCastOrTypeKindCast;
}
QualType getType() {
return T;
}
CStyleCastExpr* getCast() {
return CSCE;
}
QualType getFinalType() {
if (kind==CStyleCastOrTypeKindType) {
return getType();
}
else {
return CSCE->getType();
}
}
bool operator <(const CStyleCastOrType & other) const {
if (CSCE<other.CSCE) return true;
if (CSCE>other.CSCE) return false;
if (T<other.T) return true;
if (other.T<T) return false;
return kind<other.kind;
}
bool operator >(const CStyleCastOrType & other) const {
if (CSCE>other.CSCE) return true;
if (CSCE<other.CSCE) return false;
if (other.T<T) return true;
if (T<other.T) return false;
return kind>other.kind;
}
bool operator==(const CStyleCastOrType & other) const {
return (CSCE==other.CSCE)&&(T==other.T)&&(kind==other.kind);
}
};
/* Gets the first c-style cast saved in the cache unless there isn't one. In such case
takes first cast whatsoever (which must be implicit cast) */
static inline CStyleCastOrType getMatchingCast(std::vector<CStyleCastOrType>& vC) {
auto i = vC.begin();
for (; i!=vC.end(); ++i) {
if ((*i).isCast()) {
break;
}
}
if (i==vC.end()) {
i = vC.begin();
}
return *i;
}
static inline CStyleCastExpr* getFirstCast(std::vector<CStyleCastOrType>& vC) {
auto i = vC.begin();
for (; i!=vC.end(); ++i) {
if ((*i).isCast()) {
return (*i).getCast();
}
}
return 0;
}
bool isPtrToVoid(QualType T) {
if (T->getTypeClass()==Type::Pointer) {
const PointerType *tp = cast<PointerType>(T);
QualType ptrT = tp->getPointeeType();
if (ptrT->getTypeClass()==Type::Builtin) {
const BuiltinType *btp = cast<BuiltinType>(ptrT);
if (btp->getName(Context.getPrintingPolicy())=="void") {
return true;
}
}
}
return false;
}
struct ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS {
enum ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKind {
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindNone,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindValue,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCall,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAddress,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindInteger,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindFloating,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindString,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindMemberExpr,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindUnary,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAS,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCAO,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindOOE,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRET,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindParm,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCond,
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindLogic,
};
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(): value(0), call(0), address(0), floating(0.), strval(""), ME(0), MEIdx(0), MECnt(0),
UO(0), AS(0), valuecast(), cao(0), ooe(0), re(0), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindNone), primary(true) {}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(const ValueDecl* value): value(value), call(0), address(0), floating(0.), strval(""), ME(0), MEIdx(0), MECnt(0),
UO(0), AS(0), valuecast(), cao(0), ooe(0), re(0), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindValue), primary(true) {}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(const CallExpr* call): value(0), call(call), address(0), floating(0.), strval(""), ME(0), MEIdx(0), MECnt(0),
UO(0), AS(0), valuecast(), cao(0), ooe(0), re(0), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCall), primary(true) {}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(int64_t address): value(0), call(0), address(address), floating(0.), strval(""), ME(0), MEIdx(0), MECnt(0),
UO(0), AS(0), valuecast(), cao(0), ooe(0), re(0), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAddress), primary(true) {}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(const MemberExpr* ME): value(0), call(0), address(0), floating(0.), strval(""), ME(ME), MEIdx(0), MECnt(0),
UO(0), AS(0), valuecast(), cao(0), ooe(0), re(0), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindMemberExpr), primary(true) {}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(const UnaryOperator* UO): value(0), call(0), address(0), floating(0.), strval(""), ME(0), MEIdx(0), MECnt(0),
UO(UO), AS(0), valuecast(), cao(0), ooe(0), re(0), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindUnary), primary(true) {}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(const ArraySubscriptExpr* AS): value(0), call(0), address(0), floating(0.), strval(""), ME(0), MEIdx(0), MECnt(0),
UO(0), AS(AS), valuecast(), cao(0), ooe(0), re(0), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAS), primary(true) {}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(const CompoundAssignOperator* CAO): value(0), call(0), address(0), floating(0.), strval(""), ME(0), MEIdx(0), MECnt(0),
UO(0), AS(0), valuecast(), cao(CAO), ooe(0), re(0), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCAO), primary(true) {}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(const OffsetOfExpr* OOE): value(0), call(0), address(0), floating(0.), strval(""), ME(0), MEIdx(0), MECnt(0),
UO(0), AS(0), valuecast(), cao(0), ooe(OOE), re(0), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindOOE), primary(true) {}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS(const ReturnStmt *S): value(0), call(0), address(0), floating(0.), strval(""), ME(0), MEIdx(0), MECnt(0),
UO(0), AS(0), valuecast(), cao(0), ooe(0), re(S->getRetValue()), kind(ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRET), primary(true) {}
const ValueDecl* value;
const CallExpr* call;
int64_t address;
double floating;
std::string strval;
const MemberExpr* ME;
QualType METype;
unsigned MEIdx;
unsigned MECnt;
const UnaryOperator* UO;
const ArraySubscriptExpr* AS;
CStyleCastOrType valuecast;
const BinaryOperator* cao;
const OffsetOfExpr* ooe;
const Expr* re;
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKind kind;
bool primary;
bool isPrimary() {
return primary;
}
void setPrimaryFlag(bool __primary) {
primary = __primary;
}
ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKind getKind() {
return kind;
}
std::string getKindString() {
switch(kind) {
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindNone:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindNone";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindValue:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindValue";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCall:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCall";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAddress:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAddress";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindFloating:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindFloating";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindString:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindString";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindInteger:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindInteger";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindMemberExpr:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindMemberExpr";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindUnary:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindUnary";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAS:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAS";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCAO:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCAO";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindOOE:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindOOE";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRET:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRET";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindParm:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindParm";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCond:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCond";
case ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindLogic:
return "ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindLogic";
}
return "";
}
const ValueDecl* getValue() {
return value;
}
CStyleCastOrType getValueCast() {
return valuecast;
}
const CallExpr* getCall() {
return call;
}
int64_t getAddress() {
return address;
}
int64_t getInteger() {
return address;
}
double getFloating() {
return floating;
}
std::string getString() {
return strval;
}
void getCompound() {
}
std::pair<const MemberExpr*,QualType> getME() {
return std::pair<const MemberExpr*,QualType>(ME,METype);
}
unsigned getMeIdx() {
return MEIdx;
}
unsigned getMeCnt() {
return MECnt;
}
const UnaryOperator* getUnary() {
return UO;
}
const ArraySubscriptExpr* getAS() {
return AS;
}
const BinaryOperator* getCAO() {
return cao;
}
const BinaryOperator* getLogic() {
return cao;
}
const OffsetOfExpr* getOOE() {
return ooe;
}
const Expr* getRET() {
return re;
}
const Expr* getParm() {
return re;
}
void setCast(CStyleCastOrType cast) {
valuecast = cast;
}
void setValue(const ValueDecl* v, CStyleCastOrType cast = CStyleCastOrType()) {
value = v;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindValue;
}
void setCall(const CallExpr* c, CStyleCastOrType cast = CStyleCastOrType()) {
call = c;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCall;
}
void setCAO(const BinaryOperator* CAO, CStyleCastOrType cast = CStyleCastOrType()) {
cao = CAO;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCAO;
}
void setLogic(const BinaryOperator* CAO, CStyleCastOrType cast = CStyleCastOrType()) {
cao = CAO;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindLogic;
}
void setOOE(const OffsetOfExpr* OOE, CStyleCastOrType cast = CStyleCastOrType()) {
ooe = OOE;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindOOE;
}
void setRET(const ReturnStmt* S, CStyleCastOrType cast = CStyleCastOrType()) {
re = S->getRetValue();
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRET;
}
void setParm(const Expr* E, CStyleCastOrType cast = CStyleCastOrType()) {
re = E;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindParm;
}
void setCond(const Expr *E,size_t cf_id, CStyleCastOrType cast = CStyleCastOrType()){
re = E;
address = cf_id;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindCond;
}
void setRefCall(const CallExpr* c, const UnaryOperator* __UO, CStyleCastOrType cast = CStyleCastOrType()) {
call = c;
UO = __UO;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall;
}
void setRefCall(const CallExpr* c, const ArraySubscriptExpr* __AS, CStyleCastOrType cast = CStyleCastOrType()) {
call = c;
AS = __AS;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall;
}
void setRefCall(const CallExpr* c, const ValueDecl* VD, CStyleCastOrType cast = CStyleCastOrType()) {
call = c;
value = VD;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall;
}
void setRefCall(const CallExpr* c, int64_t a, CStyleCastOrType cast = CStyleCastOrType()) {
call = c;
address = a;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall;
}
void setRefCall(const CallExpr* c, const BinaryOperator* CAO, CStyleCastOrType cast = CStyleCastOrType()) {
call = c;
cao = CAO;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall;
}
void setRefCall(const CallExpr* c, const OffsetOfExpr* OOE, CStyleCastOrType cast = CStyleCastOrType()) {
call = c;
ooe = OOE;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall;
}
void setRefCall(const CallExpr* c, const ReturnStmt* S, CStyleCastOrType cast = CStyleCastOrType()) {
call = c;
re = S->getRetValue();
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindRefCall;
}
void setAddress(int64_t a, CStyleCastOrType cast = CStyleCastOrType()) {
address = a;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAddress;
}
void setInteger(int64_t a, CStyleCastOrType cast = CStyleCastOrType()) {
address = a;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindInteger;
}
void setFloating(double f, CStyleCastOrType cast = CStyleCastOrType()) {
floating = f;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindFloating;
}
void setString(std::string s, CStyleCastOrType cast = CStyleCastOrType()) {
strval = s;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindString;
}
void setME(const MemberExpr* __ME, QualType __METype, CStyleCastOrType cast = CStyleCastOrType()) {
ME = __ME;
METype = __METype;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindMemberExpr;
}
void setMeIdx(unsigned __MEIdx) {
MEIdx = __MEIdx;
}
void setMeCnt(unsigned __MECnt) {
MECnt = __MECnt;
}
void setUnary(const UnaryOperator* __UO, CStyleCastOrType cast = CStyleCastOrType()) {
UO = __UO;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindUnary;
}
void setAS(const ArraySubscriptExpr* __AS, CStyleCastOrType cast = CStyleCastOrType()) {
AS = __AS;
valuecast = cast;
kind = ValueDeclOrCallExprOrAddressOrMEOrUnaryOrASKindAS;
}
bool operator <(const ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS & otherVC) const {
if (kind<otherVC.kind) return true;
if (kind>otherVC.kind) return false;
if (MEIdx<otherVC.MEIdx) return true;
if (MEIdx>otherVC.MEIdx) return false;
if (MECnt<otherVC.MECnt) return true;
if (MECnt>otherVC.MECnt) return false;
if (value<otherVC.value) return true;
if (value>otherVC.value) return false;
if (address<otherVC.address) return true;
if (address>otherVC.address) return false;
if (floating<otherVC.floating) return true;
if (floating>otherVC.floating) return false;
if (strval<otherVC.strval) return true;
if (strval>otherVC.strval) return false;
if (call<otherVC.call) return true;
if (call>otherVC.call) return false;
if (ME<otherVC.ME) return true;
if (ME>otherVC.ME) return false;
if (METype<otherVC.METype) return true;
if ((!(METype<otherVC.METype)) && (METype!=otherVC.METype)) return false;
if (UO<otherVC.UO) return true;
if (UO>otherVC.UO) return false;
if (valuecast<otherVC.valuecast) return true;
if (valuecast>otherVC.valuecast) return false;
if (cao<otherVC.cao) return true;
if (cao>otherVC.cao) return false;
if (ooe<otherVC.ooe) return true;
if (ooe>otherVC.ooe) return false;
if (re<otherVC.re) return true;
if (re>otherVC.re) return false;
if (primary<otherVC.primary) return true;
if (primary>otherVC.primary) return false;
return AS<otherVC.AS;
}
bool operator >(const ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS & otherVC) const {
if (kind<otherVC.kind) return false;
if (kind>otherVC.kind) return true;
if (MEIdx<otherVC.MEIdx) return false;
if (MEIdx>otherVC.MEIdx) return true;
if (MECnt<otherVC.MECnt) return false;
if (MECnt>otherVC.MECnt) return true;
if (value<otherVC.value) return false;
if (value>otherVC.value) return true;
if (address<otherVC.address) return false;
if (address>otherVC.address) return true;
if (floating<otherVC.floating) return false;
if (floating>otherVC.floating) return true;
if (strval<otherVC.strval) return false;
if (strval>otherVC.strval) return true;
if (call<otherVC.call) return false;
if (call>otherVC.call) return true;
if (ME<otherVC.ME) return false;
if (ME>otherVC.ME) return true;
if (METype<otherVC.METype) return false;
if ((!(METype<otherVC.METype)) && (METype!=otherVC.METype)) return true;
if (UO<otherVC.UO) return false;
if (UO>otherVC.UO) return true;
if (valuecast<otherVC.valuecast) return false;
if (valuecast>otherVC.valuecast) return true;
if (cao<otherVC.cao) return false;
if (cao>otherVC.cao) return true;
if (ooe<otherVC.ooe) return false;
if (ooe>otherVC.ooe) return true;
if (re<otherVC.re) return false;
if (re>otherVC.re) return true;
if (primary<otherVC.primary) return false;
if (primary>otherVC.primary) return true;
return AS>otherVC.AS;
}
bool operator==(const ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS & otherVC) const {
return (kind==otherVC.kind)&&(MEIdx==otherVC.MEIdx)&&(MECnt==otherVC.MECnt)&&(value==otherVC.value)&&
(address==otherVC.address)&&(floating==otherVC.floating)&&(strval==otherVC.strval)&&(call==otherVC.call)&&(ME==otherVC.ME)&&
(METype==otherVC.METype)&&
(UO==otherVC.UO)&&(valuecast==otherVC.valuecast)&&(cao==otherVC.cao)&&(ooe==otherVC.ooe)&&(re==otherVC.re)&&
(primary==otherVC.primary)&&(AS==otherVC.AS);
}
bool operator <(const ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS & otherVC) {
if (kind<otherVC.kind) return true;
if (kind>otherVC.kind) return false;
if (MEIdx<otherVC.MEIdx) return true;
if (MEIdx>otherVC.MEIdx) return false;
if (MECnt<otherVC.MECnt) return true;
if (MECnt>otherVC.MECnt) return false;
if (value<otherVC.value) return true;
if (value>otherVC.value) return false;
if (address<otherVC.address) return true;
if (address>otherVC.address) return false;
if (floating<otherVC.floating) return true;
if (floating>otherVC.floating) return false;
if (strval<otherVC.strval) return true;
if (strval>otherVC.strval) return false;
if (call<otherVC.call) return true;
if (call>otherVC.call) return false;
if (ME<otherVC.ME) return true;
if (ME>otherVC.ME) return false;
if (METype<otherVC.METype) return true;
if ((!(METype<otherVC.METype)) && (METype!=otherVC.METype)) return false;
if (UO<otherVC.UO) return true;
if (UO>otherVC.UO) return false;
if (valuecast<otherVC.valuecast) return true;
if (valuecast>otherVC.valuecast) return false;
if (cao<otherVC.cao) return true;
if (cao>otherVC.cao) return false;
if (ooe<otherVC.ooe) return true;
if (ooe>otherVC.ooe) return false;
if (re<otherVC.re) return true;
if (re>otherVC.re) return false;
if (primary<otherVC.primary) return true;
if (primary>otherVC.primary) return false;
return AS<otherVC.AS;
}
bool operator >(const ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS & otherVC) {
if (kind<otherVC.kind) return false;
if (kind>otherVC.kind) return true;
if (MEIdx<otherVC.MEIdx) return false;
if (MEIdx>otherVC.MEIdx) return true;
if (MECnt<otherVC.MECnt) return false;
if (MECnt>otherVC.MECnt) return true;
if (value<otherVC.value) return false;
if (value>otherVC.value) return true;
if (address<otherVC.address) return false;
if (address>otherVC.address) return true;
if (floating<otherVC.floating) return false;
if (floating>otherVC.floating) return true;
if (strval<otherVC.strval) return false;
if (strval>otherVC.strval) return true;
if (call<otherVC.call) return false;
if (call>otherVC.call) return true;
if (ME<otherVC.ME) return false;
if (ME>otherVC.ME) return true;
if (METype<otherVC.METype) return false;
if ((!(METype<otherVC.METype)) && (METype!=otherVC.METype)) return true;
if (UO<otherVC.UO) return false;
if (UO>otherVC.UO) return true;
if (valuecast<otherVC.valuecast) return false;
if (valuecast>otherVC.valuecast) return true;
if (cao<otherVC.cao) return false;
if (cao>otherVC.cao) return true;
if (ooe<otherVC.ooe) return false;
if (ooe>otherVC.ooe) return true;
if (re<otherVC.re) return false;
if (re>otherVC.re) return true;
if (primary<otherVC.primary) return false;
if (primary>otherVC.primary) return true;
return AS>otherVC.AS;
}
bool operator==(const ValueDeclOrCallExprOrAddressOrMEOrUnaryOrAS & otherVC) {
return (kind==otherVC.kind)&&(MEIdx==otherVC.MEIdx)&&(MECnt==otherVC.MECnt)&&(value==otherVC.value)&&
(address==otherVC.address)&&(floating==otherVC.floating)&&(strval==otherVC.strval)&&(call==otherVC.call)&&(ME==otherVC.ME)&&
(METype==otherVC.METype)&&
(UO==otherVC.UO)&&(valuecast==otherVC.valuecast)&&(cao==otherVC.cao)&&(ooe==otherVC.ooe)&&(re==otherVC.re)&&
(primary==otherVC.primary)&&(AS==otherVC.AS);
}
};
struct callfunc_info_t {
bool funcproto;
void* FunctionDeclOrProtoType;
size_t csid;
const CallExpr* CE;
void* refObj; // ptr
QualType classType;
unsigned fieldIndex;
std::set<ValueHolder> callrefs;
std::set<LiteralHolder> literalRefs;
size_t ord;
bool operator<(callfunc_info_t other) const {
return memcmp(this,&other,sizeof(callfunc_info_t));
}
};
struct refvarinfo_t {
unsigned long id;
double fp;
std::string s;
LiteralHolder lh;
enum vartype {
CALLVAR_NONE,
CALLVAR_FUNCTION,
CALLVAR_GLOBAL,
CALLVAR_LOCAL,
CALLVAR_LOCALPARM,
CALLVAR_STRINGLITERAL,
CALLVAR_CHARLITERAL,
CALLVAR_INTEGERLITERAL,
CALLVAR_FLOATLITERAL,
CALLVAR_CALLREF,
CALLVAR_REFCALLREF,
CALLVAR_ADDRCALLREF,
CALLVAR_ADDRESS,
CALLVAR_INTEGER,
CALLVAR_FLOATING,
CALLVAR_STRING,
CALLVAR_UNARY,
CALLVAR_ARRAY,
CALLVAR_MEMBER,
CALLVAR_ASSIGN,
CALLVAR_OFFSETOF,
CALLVAR_LOGIC,
} type;
unsigned long mi;
unsigned long di;
long castid;
refvarinfo_t(): id(-1), fp(0.), s(""), type(CALLVAR_NONE), mi(0), di(0), castid(-1) {}
refvarinfo_t(unsigned long id, enum vartype type): id(id), fp(0.), s(""), type(type), mi(0), di(0), castid(-1) {}
refvarinfo_t(unsigned long id, enum vartype type, unsigned pos): id(id), fp(0.), s(""), type(type), mi(pos), di(0), castid(-1) {}
refvarinfo_t(unsigned long id, enum vartype type, unsigned pos, double fp): id(id), fp(fp), s(""), type(type), mi(pos), di(0), castid(-1) {}
refvarinfo_t(unsigned long id, enum vartype type, unsigned pos, std::string s): id(id), fp(0.), s(s), type(type), mi(pos), di(0), castid(-1) {}
refvarinfo_t(LiteralHolder lh, enum vartype type): id(-1), fp(0.), s(""), lh(lh), type(type), mi(0), di(0), castid(-1) {}
refvarinfo_t(LiteralHolder lh, enum vartype type, unsigned pos): id(-1), fp(0.), s(""), lh(lh), type(type), mi(pos), di(0), castid(-1) {}
void set(unsigned long _id, enum vartype _type, long _mi=0, long _di=0, long _castid=-1)
{ id = _id; type = _type; mi = _mi; di = _di; castid = _castid; }
void setFp(unsigned long id, enum vartype _type, long _mi, long _di=0, long _castid=-1, double _fp=0.)
{ id = -1; fp = _fp; s = ""; type = _type; mi = _mi; di = _di; castid = _castid; }
void setString(unsigned long id, enum vartype _type, long _mi, long _di=0, long _castid=-1, std::string _s="")
{ id = -1; fp = 0.; s = _s; type = _type; mi = _mi; di = _di; castid = _castid; }
bool isLiteral() {
return (type==CALLVAR_STRINGLITERAL) || (type==CALLVAR_CHARLITERAL) ||
(type==CALLVAR_INTEGERLITERAL) || (type==CALLVAR_FLOATLITERAL);
}