summaryrefslogtreecommitdiffstats
path: root/include/clang/AST/DeclCXX.h
blob: bffedfcd784f730c916207eb09d89f4ae8d833ed (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file defines the C++ Decl subclasses.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_AST_DECLCXX_H
#define LLVM_CLANG_AST_DECLCXX_H

#include "clang/AST/Expr.h"
#include "clang/AST/Decl.h"
#include "llvm/ADT/SmallVector.h"

namespace clang {

class ClassTemplateDecl;
class CXXRecordDecl;
class CXXConstructorDecl;
class CXXDestructorDecl;
class CXXConversionDecl;
class CXXMethodDecl;
class ClassTemplateSpecializationDecl;

/// \brief Represents any kind of function declaration, whether it is a 
/// concrete function or a function template.
class AnyFunctionDecl {
  NamedDecl *Function;
  
  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
  
public:
  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
  AnyFunctionDecl(FunctionTemplateDecl *FTD);
  
  /// \brief Implicily converts any function or function template into a 
  /// named declaration.
  operator NamedDecl *() const { return Function; }
  
  /// \brief Retrieve the underlying function or function template.
  NamedDecl *get() const { return Function; }
  
  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 
    return AnyFunctionDecl(ND);
  }
};
  
} // end namespace clang

namespace llvm {
  /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 
  /// AnyFunctionDecl to any function or function template declaration.
  template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
    typedef ::clang::NamedDecl* SimpleType;
    static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
      return Val;
    }
  };
  template<> struct simplify_type< ::clang::AnyFunctionDecl>
  : public simplify_type<const ::clang::AnyFunctionDecl> {};
  
  // Provide PointerLikeTypeTraits for non-cvr pointers.
  template<>
  class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
  public:
    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
      return F.get(); 
    }
    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
      return ::clang::AnyFunctionDecl::getFromNamedDecl(
                                      static_cast< ::clang::NamedDecl*>(P));
    }
    
    enum { NumLowBitsAvailable = 2 };
  };
  
} // end namespace llvm

namespace clang {
  
/// OverloadedFunctionDecl - An instance of this class represents a
/// set of overloaded functions. All of the functions have the same
/// name and occur within the same scope.
///
/// An OverloadedFunctionDecl has no ownership over the FunctionDecl
/// nodes it contains. Rather, the FunctionDecls are owned by the
/// enclosing scope (which also owns the OverloadedFunctionDecl
/// node). OverloadedFunctionDecl is used primarily to store a set of
/// overloaded functions for name lookup.
class OverloadedFunctionDecl : public NamedDecl {
protected:
  OverloadedFunctionDecl(DeclContext *DC, DeclarationName N)
    : NamedDecl(OverloadedFunction, DC, SourceLocation(), N) { }

  /// Functions - the set of overloaded functions contained in this
  /// overload set.
  llvm::SmallVector<AnyFunctionDecl, 4> Functions;

  // FIXME: This should go away when we stop using
  // OverloadedFunctionDecl to store conversions in CXXRecordDecl.
  friend class CXXRecordDecl;

public:
  typedef llvm::SmallVector<AnyFunctionDecl, 4>::iterator function_iterator;
  typedef llvm::SmallVector<AnyFunctionDecl, 4>::const_iterator
    function_const_iterator;

  static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
                                        DeclarationName N);

  /// \brief Add a new overloaded function or function template to the set
  /// of overloaded function templates.
  void addOverload(AnyFunctionDecl F);

  function_iterator function_begin() { return Functions.begin(); }
  function_iterator function_end() { return Functions.end(); }
  function_const_iterator function_begin() const { return Functions.begin(); }
  function_const_iterator function_end() const { return Functions.end(); }

  /// \brief Returns the number of overloaded functions stored in
  /// this set.
  unsigned size() const { return Functions.size(); }

  // Implement isa/cast/dyncast/etc.
  static bool classof(const Decl *D) { 
    return D->getKind() == OverloadedFunction; 
  }
  static bool classof(const OverloadedFunctionDecl *D) { return true; }
};
  
/// \brief Provides uniform iteration syntax for an overload set, function, 
/// or function template.
class OverloadIterator {
  /// \brief An overloaded function set, function declaration, or
  /// function template declaration.
  NamedDecl *D;
  
  /// \brief If the declaration is an overloaded function set, this is the
  /// iterator pointing to the current position within that overloaded
  /// function set.
  OverloadedFunctionDecl::function_iterator Iter;
  
public:
  typedef AnyFunctionDecl value_type;
  typedef value_type      reference;
  typedef NamedDecl      *pointer;
  typedef int             difference_type;
  typedef std::forward_iterator_tag iterator_category;
  
  OverloadIterator() : D(0) { }
  
  OverloadIterator(FunctionDecl *FD) : D(FD) { }
  OverloadIterator(FunctionTemplateDecl *FTD) 
    : D(reinterpret_cast<NamedDecl*>(FTD)) { }
  OverloadIterator(OverloadedFunctionDecl *Ovl) 
    : D(Ovl), Iter(Ovl->function_begin()) { }
  
  OverloadIterator(NamedDecl *ND);
  
  reference operator*() const;
  
  pointer operator->() const { return (**this).get(); }
  
  OverloadIterator &operator++();
  
  OverloadIterator operator++(int) {
    OverloadIterator Temp(*this);
    ++(*this);
    return Temp;
  }
  
  bool Equals(const OverloadIterator &Other) const;
};
  
inline bool operator==(const OverloadIterator &X, const OverloadIterator &Y) {
  return X.Equals(Y);
}

inline bool operator!=(const OverloadIterator &X, const OverloadIterator &Y) {
  return !(X == Y);
}

/// CXXBaseSpecifier - A base class of a C++ class.
///
/// Each CXXBaseSpecifier represents a single, direct base class (or
/// struct) of a C++ class (or struct). It specifies the type of that
/// base class, whether it is a virtual or non-virtual base, and what
/// level of access (public, protected, private) is used for the
/// derivation. For example:
///
/// @code
///   class A { };
///   class B { };
///   class C : public virtual A, protected B { };
/// @endcode
///
/// In this code, C will have two CXXBaseSpecifiers, one for "public
/// virtual A" and the other for "protected B".
class CXXBaseSpecifier {
  /// Range - The source code range that covers the full base
  /// specifier, including the "virtual" (if present) and access
  /// specifier (if present).
  SourceRange Range;

  /// Virtual - Whether this is a virtual base class or not.
  bool Virtual : 1;

  /// BaseOfClass - Whether this is the base of a class (true) or of a
  /// struct (false). This determines the mapping from the access
  /// specifier as written in the source code to the access specifier
  /// used for semantic analysis.
  bool BaseOfClass : 1; 

  /// Access - Access specifier as written in the source code (which
  /// may be AS_none). The actual type of data stored here is an
  /// AccessSpecifier, but we use "unsigned" here to work around a
  /// VC++ bug.
  unsigned Access : 2;

  /// BaseType - The type of the base class. This will be a class or
  /// struct (or a typedef of such).
  QualType BaseType;
  
public:
  CXXBaseSpecifier() { }

  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
    : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }

  /// getSourceRange - Retrieves the source range that contains the
  /// entire base specifier.
  SourceRange getSourceRange() const { return Range; }
  
  /// isVirtual - Determines whether the base class is a virtual base
  /// class (or not).
  bool isVirtual() const { return Virtual; }

  /// getAccessSpecifier - Returns the access specifier for this base
  /// specifier. This is the actual base specifier as used for
  /// semantic analysis, so the result can never be AS_none. To
  /// retrieve the access specifier as written in the source code, use
  /// getAccessSpecifierAsWritten().
  AccessSpecifier getAccessSpecifier() const { 
    if ((AccessSpecifier)Access == AS_none)
      return BaseOfClass? AS_private : AS_public;
    else
      return (AccessSpecifier)Access; 
  }

  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
  /// written in the source code (which may mean that no access
  /// specifier was explicitly written). Use getAccessSpecifier() to
  /// retrieve the access specifier for use in semantic analysis.
  AccessSpecifier getAccessSpecifierAsWritten() const {
    return (AccessSpecifier)Access;
  }

  /// getType - Retrieves the type of the base class. This type will
  /// always be an unqualified class type.
  QualType getType() const { return BaseType; }
};

/// CXXRecordDecl - Represents a C++ struct/union/class.
/// FIXME: This class will disappear once we've properly taught RecordDecl
/// to deal with C++-specific things.
class CXXRecordDecl : public RecordDecl {
  /// UserDeclaredConstructor - True when this class has a
  /// user-declared constructor. 
  bool UserDeclaredConstructor : 1;

  /// UserDeclaredCopyConstructor - True when this class has a
  /// user-declared copy constructor.
  bool UserDeclaredCopyConstructor : 1;

  /// UserDeclaredCopyAssignment - True when this class has a
  /// user-declared copy assignment operator.
  bool UserDeclaredCopyAssignment : 1;

  /// UserDeclaredDestructor - True when this class has a
  /// user-declared destructor.
  bool UserDeclaredDestructor : 1;

  /// Aggregate - True when this class is an aggregate.
  bool Aggregate : 1;

  /// PlainOldData - True when this class is a POD-type.
  bool PlainOldData : 1;

  /// Empty - true when this class is empty for traits purposes, i.e. has no
  /// data members other than 0-width bit-fields, has no virtual function/base,
  /// and doesn't inherit from a non-empty class. Doesn't take union-ness into
  /// account.
  bool Empty : 1;

  /// Polymorphic - True when this class is polymorphic, i.e. has at least one
  /// virtual member or derives from a polymorphic class.
  bool Polymorphic : 1;

  /// Abstract - True when this class is abstract, i.e. has at least one
  /// pure virtual function, (that can come from a base class).
  bool Abstract : 1;

  /// HasTrivialConstructor - True when this class has a trivial constructor.
  ///
  /// C++ [class.ctor]p5.  A constructor is trivial if it is an
  /// implicitly-declared default constructor and if:
  /// * its class has no virtual functions and no virtual base classes, and
  /// * all the direct base classes of its class have trivial constructors, and
  /// * for all the nonstatic data members of its class that are of class type
  ///   (or array thereof), each such class has a trivial constructor.
  bool HasTrivialConstructor : 1;
  
  /// HasTrivialCopyConstructor - True when this class has a trivial copy
  /// constructor.
  ///
  /// C++ [class.copy]p6.  A copy constructor for class X is trivial
  /// if it is implicitly declared and if
  /// * class X has no virtual functions and no virtual base classes, and
  /// * each direct base class of X has a trivial copy constructor, and
  /// * for all the nonstatic data members of X that are of class type (or
  ///   array thereof), each such class type has a trivial copy constructor;
  /// otherwise the copy constructor is non-trivial.
  bool HasTrivialCopyConstructor : 1;

  /// HasTrivialCopyAssignment - True when this class has a trivial copy
  /// assignment operator.
  ///
  /// C++ [class.copy]p11.  A copy assignment operator for class X is
  /// trivial if it is implicitly declared and if
  /// * class X has no virtual functions and no virtual base classes, and
  /// * each direct base class of X has a trivial copy assignment operator, and
  /// * for all the nonstatic data members of X that are of class type (or
  ///   array thereof), each such class type has a trivial copy assignment
  ///   operator;
  /// otherwise the copy assignment operator is non-trivial.
  bool HasTrivialCopyAssignment : 1;
  
  /// HasTrivialDestructor - True when this class has a trivial destructor.
  ///
  /// C++ [class.dtor]p3.  A destructor is trivial if it is an
  /// implicitly-declared destructor and if:
  /// * all of the direct base classes of its class have trivial destructors
  ///   and
  /// * for all of the non-static data members of its class that are of class
  ///   type (or array thereof), each such class has a trivial destructor.
  bool HasTrivialDestructor : 1;

  /// Bases - Base classes of this class.
  /// FIXME: This is wasted space for a union.
  CXXBaseSpecifier *Bases;

  /// NumBases - The number of base class specifiers in Bases.
  unsigned NumBases;

  /// VBases - direct and indirect virtual base classes of this class.
  CXXBaseSpecifier *VBases;
  
  /// NumVBases - The number of virtual base class specifiers in VBases.
  unsigned NumVBases;
  
  /// Conversions - Overload set containing the conversion functions
  /// of this C++ class (but not its inherited conversion
  /// functions). Each of the entries in this overload set is a
  /// CXXConversionDecl.
  OverloadedFunctionDecl Conversions;

  /// \brief The template or declaration that this declaration
  /// describes or was instantiated from, respectively.
  /// 
  /// For non-templates, this value will be NULL. For record
  /// declarations that describe a class template, this will be a
  /// pointer to a ClassTemplateDecl. For member
  /// classes of class template specializations, this will be the
  /// RecordDecl from which the member class was instantiated.
  llvm::PointerUnion<ClassTemplateDecl*, CXXRecordDecl*>
    TemplateOrInstantiation;

protected:
  CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
                SourceLocation L, IdentifierInfo *Id,
                CXXRecordDecl *PrevDecl,
                SourceLocation TKL = SourceLocation());

  ~CXXRecordDecl();

public:
  /// base_class_iterator - Iterator that traverses the base classes
  /// of a class.
  typedef CXXBaseSpecifier*       base_class_iterator;

  /// base_class_const_iterator - Iterator that traverses the base
  /// classes of a class.
  typedef const CXXBaseSpecifier* base_class_const_iterator;

  /// reverse_base_class_iterator = Iterator that traverses the base classes
  /// of a class in reverse order.
  typedef std::reverse_iterator<base_class_iterator>
    reverse_base_class_iterator;

  /// reverse_base_class_iterator = Iterator that traverses the base classes
  /// of a class in reverse order.
 typedef std::reverse_iterator<base_class_const_iterator>
   reverse_base_class_const_iterator;

  static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
                               SourceLocation L, IdentifierInfo *Id,
                               SourceLocation TKL = SourceLocation(),
                               CXXRecordDecl* PrevDecl=0,
                               bool DelayTypeCreation = false);
  
  virtual void Destroy(ASTContext& C);
  
  bool isDynamicClass() const {
    return Polymorphic || NumVBases!=0;
  }

  /// setBases - Sets the base classes of this struct or class.
  void setBases(ASTContext &C,
                CXXBaseSpecifier const * const *Bases, unsigned NumBases);

  /// getNumBases - Retrieves the number of base classes of this
  /// class.
  unsigned getNumBases() const { return NumBases; }

  base_class_iterator       bases_begin()       { return Bases; }
  base_class_const_iterator bases_begin() const { return Bases; }
  base_class_iterator       bases_end()         { return Bases + NumBases; }
  base_class_const_iterator bases_end()   const { return Bases + NumBases; }
  reverse_base_class_iterator       bases_rbegin() {
    return reverse_base_class_iterator(bases_end());
  }
  reverse_base_class_const_iterator bases_rbegin() const {
    return reverse_base_class_const_iterator(bases_end());
  }
  reverse_base_class_iterator bases_rend() {
    return reverse_base_class_iterator(bases_begin());
  }
  reverse_base_class_const_iterator bases_rend() const {
    return reverse_base_class_const_iterator(bases_begin());
  }
  
  /// getNumVBases - Retrieves the number of virtual base classes of this
  /// class.
  unsigned getNumVBases() const { return NumVBases; }
  
  base_class_iterator       vbases_begin()       { return VBases; }
  base_class_const_iterator vbases_begin() const { return VBases; }
  base_class_iterator       vbases_end()         { return VBases + NumVBases; }
  base_class_const_iterator vbases_end()   const { return VBases + NumVBases; }
  reverse_base_class_iterator vbases_rbegin() {
    return reverse_base_class_iterator(vbases_end());
  }
  reverse_base_class_const_iterator vbases_rbegin() const {
    return reverse_base_class_const_iterator(vbases_end());
  }
  reverse_base_class_iterator vbases_rend() {
    return reverse_base_class_iterator(vbases_begin());
  }
  reverse_base_class_const_iterator vbases_rend() const {
    return reverse_base_class_const_iterator(vbases_begin());
 }

  /// Iterator access to method members.  The method iterator visits
  /// all method members of the class, including non-instance methods,
  /// special methods, etc.
  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
  
  /// method_begin - Method begin iterator.  Iterates in the order the methods
  /// were declared.
  method_iterator method_begin() const {
    return method_iterator(decls_begin());
  }
  /// method_end - Method end iterator.
  method_iterator method_end() const {
    return method_iterator(decls_end());
  }

  /// Iterator access to constructor members.
  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
  
  ctor_iterator ctor_begin() const {
    return ctor_iterator(decls_begin());
  }
  ctor_iterator ctor_end() const {
    return ctor_iterator(decls_end());
  }

  /// hasConstCopyConstructor - Determines whether this class has a
  /// copy constructor that accepts a const-qualified argument.
  bool hasConstCopyConstructor(ASTContext &Context) const;

  /// getCopyConstructor - Returns the copy constructor for this class
  CXXConstructorDecl *getCopyConstructor(ASTContext &Context, 
                                         unsigned TypeQuals) const;

  /// hasConstCopyAssignment - Determines whether this class has a
  /// copy assignment operator that accepts a const-qualified argument.
  /// It returns its decl in MD if found.
  bool hasConstCopyAssignment(ASTContext &Context, 
                              const CXXMethodDecl *&MD) const;

  /// addedConstructor - Notify the class that another constructor has
  /// been added. This routine helps maintain information about the
  /// class based on which constructors have been added.
  void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);

  /// hasUserDeclaredConstructor - Whether this class has any
  /// user-declared constructors. When true, a default constructor
  /// will not be implicitly declared.
  bool hasUserDeclaredConstructor() const { return UserDeclaredConstructor; }

  /// hasUserDeclaredCopyConstructor - Whether this class has a
  /// user-declared copy constructor. When false, a copy constructor
  /// will be implicitly declared.
  bool hasUserDeclaredCopyConstructor() const {
    return UserDeclaredCopyConstructor;
  }

  /// addedAssignmentOperator - Notify the class that another assignment
  /// operator has been added. This routine helps maintain information about the
   /// class based on which operators have been added.
  void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);

  /// hasUserDeclaredCopyAssignment - Whether this class has a
  /// user-declared copy assignment operator. When false, a copy
  /// assigment operator will be implicitly declared.
  bool hasUserDeclaredCopyAssignment() const {
    return UserDeclaredCopyAssignment;
  }

  /// hasUserDeclaredDestructor - Whether this class has a
  /// user-declared destructor. When false, a destructor will be
  /// implicitly declared.
  bool hasUserDeclaredDestructor() const { return UserDeclaredDestructor; }

  /// setUserDeclaredDestructor - Set whether this class has a
  /// user-declared destructor. If not set by the time the class is
  /// fully defined, a destructor will be implicitly declared.
  void setUserDeclaredDestructor(bool UCD) { 
    UserDeclaredDestructor = UCD; 
  }

  /// getConversions - Retrieve the overload set containing all of the
  /// conversion functions in this class.
  OverloadedFunctionDecl *getConversionFunctions() { 
    return &Conversions; 
  }
  const OverloadedFunctionDecl *getConversionFunctions() const { 
    return &Conversions; 
  }

  /// addConversionFunction - Add a new conversion function to the
  /// list of conversion functions.
  void addConversionFunction(ASTContext &Context, CXXConversionDecl *ConvDecl);

  /// isAggregate - Whether this class is an aggregate (C++
  /// [dcl.init.aggr]), which is a class with no user-declared
  /// constructors, no private or protected non-static data members,
  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
  bool isAggregate() const { return Aggregate; }

  /// setAggregate - Set whether this class is an aggregate (C++
  /// [dcl.init.aggr]).
  void setAggregate(bool Agg) { Aggregate = Agg; }

  /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
  /// that is an aggregate that has no non-static non-POD data members, no
  /// reference data members, no user-defined copy assignment operator and no
  /// user-defined destructor.
  bool isPOD() const { return PlainOldData; }

  /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
  void setPOD(bool POD) { PlainOldData = POD; }

  /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
  /// means it has a virtual function, virtual base, data member (other than
  /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
  /// a check for union-ness.
  bool isEmpty() const { return Empty; }

  /// Set whether this class is empty (C++0x [meta.unary.prop])
  void setEmpty(bool Emp) { Empty = Emp; }

  /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
  /// which means that the class contains or inherits a virtual function.
  bool isPolymorphic() const { return Polymorphic; }

  /// setPolymorphic - Set whether this class is polymorphic (C++
  /// [class.virtual]).
  void setPolymorphic(bool Poly) { Polymorphic = Poly; }

  /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
  /// which means that the class contains or inherits a pure virtual function.
  bool isAbstract() const { return Abstract; }
  
  /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
  void setAbstract(bool Abs) { Abstract = Abs; }
  
  // hasTrivialConstructor - Whether this class has a trivial constructor
  // (C++ [class.ctor]p5)
  bool hasTrivialConstructor() const { return HasTrivialConstructor; }
  
  // setHasTrivialConstructor - Set whether this class has a trivial constructor
  // (C++ [class.ctor]p5)
  void setHasTrivialConstructor(bool TC) { HasTrivialConstructor = TC; }
  
  // hasTrivialCopyConstructor - Whether this class has a trivial copy
  // constructor (C++ [class.copy]p6)
  bool hasTrivialCopyConstructor() const { return HasTrivialCopyConstructor; }
  
  // setHasTrivialCopyConstructor - Set whether this class has a trivial
  // copy constructor (C++ [class.copy]p6)
  void setHasTrivialCopyConstructor(bool TC) { HasTrivialCopyConstructor = TC; }

  // hasTrivialCopyAssignment - Whether this class has a trivial copy
  // assignment operator (C++ [class.copy]p11)
  bool hasTrivialCopyAssignment() const { return HasTrivialCopyAssignment; }
  
  // setHasTrivialCopyAssignment - Set whether this class has a
  // trivial copy assignment operator (C++ [class.copy]p11)
  void setHasTrivialCopyAssignment(bool TC) { HasTrivialCopyAssignment = TC; }

  // hasTrivialDestructor - Whether this class has a trivial destructor
  // (C++ [class.dtor]p3)
  bool hasTrivialDestructor() const { return HasTrivialDestructor; }
  
  // setHasTrivialDestructor - Set whether this class has a trivial destructor
  // (C++ [class.dtor]p3)
  void setHasTrivialDestructor(bool TC) { HasTrivialDestructor = TC; }
  
  /// \brief If this record is an instantiation of a member class,
  /// retrieves the member class from which it was instantiated.
  ///
  /// This routine will return non-NULL for (non-templated) member
  /// classes of class templates. For example, given:
  ///
  /// \code
  /// template<typename T>
  /// struct X {
  ///   struct A { };
  /// };
  /// \endcode
  ///
  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
  /// whose parent is the class template specialization X<int>. For
  /// this declaration, getInstantiatedFromMemberClass() will return
  /// the CXXRecordDecl X<T>::A. When a complete definition of
  /// X<int>::A is required, it will be instantiated from the
  /// declaration returned by getInstantiatedFromMemberClass().
  CXXRecordDecl *getInstantiatedFromMemberClass() const {
    return TemplateOrInstantiation.dyn_cast<CXXRecordDecl*>();
  }

  /// \brief Specify that this record is an instantiation of the
  /// member class RD.
  void setInstantiationOfMemberClass(CXXRecordDecl *RD) { 
    TemplateOrInstantiation = RD;
  }

  /// \brief Retrieves the class template that is described by this
  /// class declaration.
  ///
  /// Every class template is represented as a ClassTemplateDecl and a
  /// CXXRecordDecl. The former contains template properties (such as
  /// the template parameter lists) while the latter contains the
  /// actual description of the template's
  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
  /// CXXRecordDecl that from a ClassTemplateDecl, while
  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
  /// a CXXRecordDecl.
  ClassTemplateDecl *getDescribedClassTemplate() const {
    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
  }

  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
    TemplateOrInstantiation = Template;
  }

  /// getDefaultConstructor - Returns the default constructor for this class
  CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
  
  /// getDestructor - Returns the destructor decl for this class.
  const CXXDestructorDecl *getDestructor(ASTContext &Context);
  
  /// isLocalClass - If the class is a local class [class.local], returns
  /// the enclosing function declaration.
  const FunctionDecl *isLocalClass() const {
    if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
      return RD->isLocalClass();
    
    return dyn_cast<FunctionDecl>(getDeclContext());
  }
  
  /// viewInheritance - Renders and displays an inheritance diagram
  /// for this C++ class and all of its base classes (transitively) using
  /// GraphViz.
  void viewInheritance(ASTContext& Context) const;

  static bool classof(const Decl *D) { 
    return D->getKind() == CXXRecord || 
           D->getKind() == ClassTemplateSpecialization ||
           D->getKind() == ClassTemplatePartialSpecialization; 
  }
  static bool classof(const CXXRecordDecl *D) { return true; }
  static bool classof(const ClassTemplateSpecializationDecl *D) { 
    return true; 
  }
};

/// CXXMethodDecl - Represents a static or instance method of a
/// struct/union/class.
class CXXMethodDecl : public FunctionDecl {
protected:
  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
                DeclarationName N, QualType T, DeclaratorInfo *DInfo,
                bool isStatic, bool isInline)
    : FunctionDecl(DK, RD, L, N, T, DInfo, (isStatic ? Static : None),
                   isInline) {}

public:
  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
                              SourceLocation L, DeclarationName N,
                              QualType T, DeclaratorInfo *DInfo,
                              bool isStatic = false,
                              bool isInline = false);
  
  bool isStatic() const { return getStorageClass() == Static; }
  bool isInstance() const { return !isStatic(); }

  bool isVirtual() const { 
    return isVirtualAsWritten() ||
      (begin_overridden_methods() != end_overridden_methods());
  }

  /// 
  void addOverriddenMethod(const CXXMethodDecl *MD);
  
  typedef const CXXMethodDecl ** method_iterator;
  
  method_iterator begin_overridden_methods() const;
  method_iterator end_overridden_methods() const;
  
  /// getParent - Returns the parent of this method declaration, which
  /// is the class in which this method is defined.
  const CXXRecordDecl *getParent() const { 
    return cast<CXXRecordDecl>(FunctionDecl::getParent()); 
  }
  
  /// getParent - Returns the parent of this method declaration, which
  /// is the class in which this method is defined.
  CXXRecordDecl *getParent() { 
    return const_cast<CXXRecordDecl *>(
             cast<CXXRecordDecl>(FunctionDecl::getParent()));
  }

  /// getThisType - Returns the type of 'this' pointer.
  /// Should only be called for instance methods.
  QualType getThisType(ASTContext &C) const;

  unsigned getTypeQualifiers() const {
    return getType()->getAsFunctionProtoType()->getTypeQuals();
  }

  // Implement isa/cast/dyncast/etc.
  static bool classof(const Decl *D) { 
    return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion;
  }
  static bool classof(const CXXMethodDecl *D) { return true; }
};

/// CXXBaseOrMemberInitializer - Represents a C++ base or member
/// initializer, which is part of a constructor initializer that
/// initializes one non-static member variable or one base class. For
/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
/// initializers:
///
/// @code
/// class A { };
/// class B : public A {
///   float f;
/// public:
///   B(A& a) : A(a), f(3.14159) { }
/// };
/// @endcode
class CXXBaseOrMemberInitializer {
  /// BaseOrMember - This points to the entity being initialized,
  /// which is either a base class (a Type) or a non-static data
  /// member. When the low bit is 1, it's a base
  /// class; when the low bit is 0, it's a member.
  uintptr_t BaseOrMember;

  /// Args - The arguments used to initialize the base or member.
  Stmt **Args;
  unsigned NumArgs;
  
  union {
    /// CtorToCall - For a base or member needing a constructor for their
    /// initialization, this is the constructor to call.
    CXXConstructorDecl *CtorToCall;
  
    /// AnonUnionMember - When 'BaseOrMember' is class's anonymous union
    /// data member, this field holds the FieldDecl for the member of the
    /// anonymous union being initialized.
    /// @code
    /// struct X {
    ///   X() : au_i1(123) {}
    ///   union {
    ///     int au_i1;
    ///     float au_f1;
    ///   };
    /// };
    /// @endcode
    /// In above example, BaseOrMember holds the field decl. for anonymous union
    /// and AnonUnionMember holds field decl for au_i1.
    ///
    FieldDecl *AnonUnionMember;
  };
  
  /// IdLoc - Location of the id in ctor-initializer list.
  SourceLocation IdLoc;

public:
  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
  explicit 
  CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs,
                             CXXConstructorDecl *C,
                             SourceLocation L);

  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
  explicit 
  CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs,
                             CXXConstructorDecl *C,
                             SourceLocation L);

  /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer.
  ~CXXBaseOrMemberInitializer();

  /// arg_iterator - Iterates through the member initialization
  /// arguments.
  typedef ExprIterator arg_iterator;

  /// arg_const_iterator - Iterates through the member initialization
  /// arguments.
  typedef ConstExprIterator const_arg_iterator;

  /// getBaseOrMember - get the generic 'member' representing either the field
  /// or a base class.
  void* getBaseOrMember() const { return reinterpret_cast<void*>(BaseOrMember); }
  
  /// isBaseInitializer - Returns true when this initializer is
  /// initializing a base class.
  bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; }

  /// isMemberInitializer - Returns true when this initializer is
  /// initializing a non-static data member.
  bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; }

  /// getBaseClass - If this is a base class initializer, returns the
  /// type used to specify the initializer. The resulting type will be
  /// a class type or a typedef of a class type. If this is not a base
  /// class initializer, returns NULL.
  Type *getBaseClass() { 
    if (isBaseInitializer()) 
      return reinterpret_cast<Type*>(BaseOrMember & ~0x01);
    else
      return 0;
  }

  /// getBaseClass - If this is a base class initializer, returns the
  /// type used to specify the initializer. The resulting type will be
  /// a class type or a typedef of a class type. If this is not a base
  /// class initializer, returns NULL.
  const Type *getBaseClass() const { 
    if (isBaseInitializer()) 
      return reinterpret_cast<const Type*>(BaseOrMember & ~0x01);
    else
      return 0;
  }

  /// getMember - If this is a member initializer, returns the
  /// declaration of the non-static data member being
  /// initialized. Otherwise, returns NULL.
  FieldDecl *getMember() { 
    if (isMemberInitializer())
      return reinterpret_cast<FieldDecl *>(BaseOrMember); 
    else
      return 0;
  }

  void setMember(FieldDecl * anonUnionField) {
    BaseOrMember = reinterpret_cast<uintptr_t>(anonUnionField);
  }
  
  FieldDecl *getAnonUnionMember() const {
    return AnonUnionMember;
  }
  void setAnonUnionMember(FieldDecl *anonMember) {
    AnonUnionMember = anonMember;
  }
  
  const CXXConstructorDecl *getConstructor() const { return CtorToCall; }
  
  SourceLocation getSourceLocation() const { return IdLoc; }
  
  /// arg_begin() - Retrieve an iterator to the first initializer argument.
  arg_iterator       arg_begin()       { return Args; }
  /// arg_begin() - Retrieve an iterator to the first initializer argument.
  const_arg_iterator const_arg_begin() const { return Args; }

  /// arg_end() - Retrieve an iterator past the last initializer argument.
  arg_iterator       arg_end()       { return Args + NumArgs; }
  /// arg_end() - Retrieve an iterator past the last initializer argument.
  const_arg_iterator const_arg_end() const { return Args + NumArgs; }

  /// getNumArgs - Determine the number of arguments used to
  /// initialize the member or base.
  unsigned getNumArgs() const { return NumArgs; }
};

/// CXXConstructorDecl - Represents a C++ constructor within a
/// class. For example:
/// 
/// @code
/// class X {
/// public:
///   explicit X(int); // represented by a CXXConstructorDecl.
/// };
/// @endcode
class CXXConstructorDecl : public CXXMethodDecl {
  /// Explicit - Whether this constructor is explicit.
  bool Explicit : 1;

  /// ImplicitlyDefined - Whether this constructor was implicitly
  /// defined by the compiler. When false, the constructor was defined
  /// by the user. In C++03, this flag will have the same value as
  /// Implicit. In C++0x, however, a constructor that is
  /// explicitly defaulted (i.e., defined with " = default") will have
  /// @c !Implicit && ImplicitlyDefined.
  bool ImplicitlyDefined : 1;
  
  /// Support for base and member initializers.
  /// BaseOrMemberInitializers - The arguments used to initialize the base 
  /// or member.
  CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
  unsigned NumBaseOrMemberInitializers;
  
  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
                     DeclarationName N, QualType T, DeclaratorInfo *DInfo,
                     bool isExplicit, bool isInline, bool isImplicitlyDeclared)
    : CXXMethodDecl(CXXConstructor, RD, L, N, T, DInfo, false, isInline),
      Explicit(isExplicit), ImplicitlyDefined(false),
      BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { 
    setImplicit(isImplicitlyDeclared);
  }
  virtual void Destroy(ASTContext& C);
  
public:
  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
                                    SourceLocation L, DeclarationName N,
                                    QualType T, DeclaratorInfo *DInfo,
                                    bool isExplicit,
                                    bool isInline, bool isImplicitlyDeclared);

  /// isExplicit - Whether this constructor was marked "explicit" or not.  
  bool isExplicit() const { return Explicit; }

  /// isImplicitlyDefined - Whether this constructor was implicitly
  /// defined. If false, then this constructor was defined by the
  /// user. This operation can only be invoked if the constructor has
  /// already been defined.
  bool isImplicitlyDefined(ASTContext &C) const { 
    assert(isThisDeclarationADefinition() && 
           "Can only get the implicit-definition flag once the "
           "constructor has been defined");
    return ImplicitlyDefined; 
  }

  /// setImplicitlyDefined - Set whether this constructor was
  /// implicitly defined or not.
  void setImplicitlyDefined(bool ID) { 
    assert(isThisDeclarationADefinition() && 
           "Can only set the implicit-definition flag once the constructor "
           "has been defined");
    ImplicitlyDefined = ID; 
  }
  
  /// init_iterator - Iterates through the member/base initializer list.
  typedef CXXBaseOrMemberInitializer **init_iterator;
  
  /// init_const_iterator - Iterates through the memberbase initializer list.
  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
  
  /// init_begin() - Retrieve an iterator to the first initializer.
  init_iterator       init_begin()       { return BaseOrMemberInitializers; }
  /// begin() - Retrieve an iterator to the first initializer.
  init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
  
  /// init_end() - Retrieve an iterator past the last initializer.
  init_iterator       init_end()       { 
    return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 
  }
  /// end() - Retrieve an iterator past the last initializer.
  init_const_iterator init_end() const { 
    return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 
  }
  
  /// getNumArgs - Determine the number of arguments used to
  /// initialize the member or base.
  unsigned getNumBaseOrMemberInitializers() const { 
      return NumBaseOrMemberInitializers; 
  }
  
  void setBaseOrMemberInitializers(ASTContext &C,
                              CXXBaseOrMemberInitializer **Initializers,
                              unsigned NumInitializers,
                              llvm::SmallVectorImpl<CXXBaseSpecifier *>& Bases,
                              llvm::SmallVectorImpl<FieldDecl *>&Members);
  
  /// isDefaultConstructor - Whether this constructor is a default
  /// constructor (C++ [class.ctor]p5), which can be used to
  /// default-initialize a class of this type.
  bool isDefaultConstructor() const;

  /// isCopyConstructor - Whether this constructor is a copy
  /// constructor (C++ [class.copy]p2, which can be used to copy the
  /// class. @p TypeQuals will be set to the qualifiers on the
  /// argument type. For example, @p TypeQuals would be set to @c
  /// QualType::Const for the following copy constructor:
  ///
  /// @code
  /// class X {
  /// public:
  ///   X(const X&);
  /// };
  /// @endcode
  bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const;

  /// isCopyConstructor - Whether this constructor is a copy
  /// constructor (C++ [class.copy]p2, which can be used to copy the
  /// class.
  bool isCopyConstructor(ASTContext &Context) const {
    unsigned TypeQuals = 0;
    return isCopyConstructor(Context, TypeQuals);
  }

  /// isConvertingConstructor - Whether this constructor is a
  /// converting constructor (C++ [class.conv.ctor]), which can be
  /// used for user-defined conversions.
  bool isConvertingConstructor() const;

  // Implement isa/cast/dyncast/etc.
  static bool classof(const Decl *D) { 
    return D->getKind() == CXXConstructor;
  }
  static bool classof(const CXXConstructorDecl *D) { return true; }
};

/// CXXDestructorDecl - Represents a C++ destructor within a
/// class. For example:
/// 
/// @code
/// class X {
/// public:
///   ~X(); // represented by a CXXDestructorDecl.
/// };
/// @endcode
class CXXDestructorDecl : public CXXMethodDecl {
  enum KindOfObjectToDestroy {
    VBASE = 0x1,
    DRCTNONVBASE = 0x2,
    ANYBASE = 0x3
  };

  /// ImplicitlyDefined - Whether this destructor was implicitly
  /// defined by the compiler. When false, the destructor was defined
  /// by the user. In C++03, this flag will have the same value as
  /// Implicit. In C++0x, however, a destructor that is
  /// explicitly defaulted (i.e., defined with " = default") will have
  /// @c !Implicit && ImplicitlyDefined.
  bool ImplicitlyDefined : 1;
  
  /// Support for base and member destruction.
  /// BaseOrMemberDestructions - The arguments used to destruct the base 
  /// or member. Each uintptr_t value represents one of base classes (either
  /// virtual or direct non-virtual base), or non-static data member
  /// to be destroyed. The low two bits encode the kind of object
  /// being destroyed.
  uintptr_t *BaseOrMemberDestructions;
  unsigned NumBaseOrMemberDestructions;
  
  CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
                    DeclarationName N, QualType T,
                    bool isInline, bool isImplicitlyDeclared)
    : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*DInfo=*/0, false, isInline),
      ImplicitlyDefined(false),
      BaseOrMemberDestructions(0), NumBaseOrMemberDestructions(0) { 
    setImplicit(isImplicitlyDeclared);
  }
  virtual void Destroy(ASTContext& C);
  
public:
  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
                                   SourceLocation L, DeclarationName N,
                                   QualType T, bool isInline, 
                                   bool isImplicitlyDeclared);

  /// isImplicitlyDefined - Whether this destructor was implicitly
  /// defined. If false, then this destructor was defined by the
  /// user. This operation can only be invoked if the destructor has
  /// already been defined.
  bool isImplicitlyDefined() const { 
    assert(isThisDeclarationADefinition() && 
           "Can only get the implicit-definition flag once the destructor has been defined");
    return ImplicitlyDefined; 
  }

  /// setImplicitlyDefined - Set whether this destructor was
  /// implicitly defined or not.
  void setImplicitlyDefined(bool ID) { 
    assert(isThisDeclarationADefinition() && 
           "Can only set the implicit-definition flag once the destructor has been defined");
    ImplicitlyDefined = ID; 
  }

  /// destr_iterator - Iterates through the member/base destruction list.
   
  /// destr_const_iterator - Iterates through the member/base destruction list.
  typedef uintptr_t const destr_const_iterator;
  
  /// destr_begin() - Retrieve an iterator to the first destructed member/base.
  uintptr_t* destr_begin() { 
    return BaseOrMemberDestructions; 
  }
  /// destr_begin() - Retrieve an iterator to the first destructed member/base.
  uintptr_t* destr_begin() const { 
    return BaseOrMemberDestructions; 
  }
  
  /// destr_end() - Retrieve an iterator past the last destructed member/base.
  uintptr_t* destr_end() { 
    return BaseOrMemberDestructions + NumBaseOrMemberDestructions; 
  }
  /// destr_end() - Retrieve an iterator past the last destructed member/base.
  uintptr_t* destr_end() const { 
    return BaseOrMemberDestructions + NumBaseOrMemberDestructions; 
  }
  
  /// getNumBaseOrMemberDestructions - Number of base and non-static members
  /// to destroy.
  unsigned getNumBaseOrMemberDestructions() const { 
    return NumBaseOrMemberDestructions; 
  }
  
  /// getBaseOrMember - get the generic 'member' representing either the field
  /// or a base class.
  uintptr_t* getBaseOrMemberToDestroy() const {
    return BaseOrMemberDestructions; 
  }
  
  /// isVbaseToDestroy - returns true, if object is virtual base.
  bool isVbaseToDestroy(uintptr_t Vbase) const {
    return (Vbase & VBASE) != 0;
  }
  /// isDirectNonVBaseToDestroy - returns true, if object is direct non-virtual
  /// base.
  bool isDirectNonVBaseToDestroy(uintptr_t DrctNonVbase) const {
    return (DrctNonVbase & DRCTNONVBASE) != 0;
  }
  /// isAnyBaseToDestroy - returns true, if object is any base (virtual or 
  /// direct non-virtual)
  bool isAnyBaseToDestroy(uintptr_t AnyBase) const {
    return (AnyBase & ANYBASE) != 0;
  }
  /// isMemberToDestroy - returns true if object is a non-static data member.
  bool isMemberToDestroy(uintptr_t Member) const {
    return (Member & ANYBASE)  == 0;
  }
  /// getAnyBaseClassToDestroy - Get the type for the given base class object.
  Type *getAnyBaseClassToDestroy(uintptr_t Base) const {
    if (isAnyBaseToDestroy(Base))
      return reinterpret_cast<Type*>(Base  & ~0x03);
    return 0;
  }
  /// getMemberToDestroy - Get the member for the given object.
  FieldDecl *getMemberToDestroy(uintptr_t Member) const { 
    if (isMemberToDestroy(Member))
      return reinterpret_cast<FieldDecl *>(Member); 
    return 0;
  }
  /// getVbaseClassToDestroy - Get the virtual base.
  Type *getVbaseClassToDestroy(uintptr_t Vbase) const {
    if (isVbaseToDestroy(Vbase))
      return reinterpret_cast<Type*>(Vbase  & ~0x01);
    return 0;
  }
  /// getDirectNonVBaseClassToDestroy - Get the virtual base.
  Type *getDirectNonVBaseClassToDestroy(uintptr_t Base) const {
    if (isDirectNonVBaseToDestroy(Base))
      return reinterpret_cast<Type*>(Base  & ~0x02);
    return 0;
  }
  
  /// computeBaseOrMembersToDestroy - Compute information in current 
  /// destructor decl's AST of bases and non-static data members which will be 
  /// implicitly destroyed. We are storing the destruction in the order that
  /// they should occur (which is the reverse of construction order).
  void computeBaseOrMembersToDestroy(ASTContext &C);
                        
  // Implement isa/cast/dyncast/etc.
  static bool classof(const Decl *D) { 
    return D->getKind() == CXXDestructor;
  }
  static bool classof(const CXXDestructorDecl *D) { return true; }
};

/// CXXConversionDecl - Represents a C++ conversion function within a
/// class. For example:
/// 
/// @code
/// class X {
/// public:
///   operator bool();
/// };
/// @endcode
class CXXConversionDecl : public CXXMethodDecl {
  /// Explicit - Whether this conversion function is marked
  /// "explicit", meaning that it can only be applied when the user
  /// explicitly wrote a cast. This is a C++0x feature.
  bool Explicit : 1;

  CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
                    DeclarationName N, QualType T, DeclaratorInfo *DInfo, 
                    bool isInline, bool isExplicit)
    : CXXMethodDecl(CXXConversion, RD, L, N, T, DInfo, false, isInline),
      Explicit(isExplicit) { }

public:
  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
                                   SourceLocation L, DeclarationName N,
                                   QualType T, DeclaratorInfo *DInfo,
                                   bool isInline, bool isExplicit);

  /// isExplicit - Whether this is an explicit conversion operator
  /// (C++0x only). Explicit conversion operators are only considered
  /// when the user has explicitly written a cast.
  bool isExplicit() const { return Explicit; }

  /// getConversionType - Returns the type that this conversion
  /// function is converting to.
  QualType getConversionType() const { 
    return getType()->getAsFunctionType()->getResultType(); 
  }

  // Implement isa/cast/dyncast/etc.
  static bool classof(const Decl *D) { 
    return D->getKind() == CXXConversion;
  }
  static bool classof(const CXXConversionDecl *D) { return true; }
};

/// FriendFunctionDecl - Represents the declaration (and possibly
/// the definition) of a friend function.  For example:
///
/// @code
/// class A {
///   friend int foo(int);
/// };
/// @endcode
class FriendFunctionDecl : public FunctionDecl {
  // Location of the 'friend' specifier.
  const SourceLocation FriendLoc;

  FriendFunctionDecl(DeclContext *DC, SourceLocation L,
                     DeclarationName N, QualType T, DeclaratorInfo *DInfo,
                     bool isInline, SourceLocation FriendL)
    : FunctionDecl(FriendFunction, DC, L, N, T, DInfo, None, isInline),
      FriendLoc(FriendL)
  {}

public:
  static FriendFunctionDecl *Create(ASTContext &C, DeclContext *DC,
                                    SourceLocation L, DeclarationName N,
                                    QualType T, DeclaratorInfo *DInfo,
                                    bool isInline, SourceLocation FriendL);

  SourceLocation getFriendLoc() const {
    return FriendLoc;
  }

  // Implement isa/cast/dyncast/etc.
  static bool classof(const Decl *D) { 
    return D->getKind() == FriendFunction;
  }
  static bool classof(const FriendFunctionDecl *D) { return true; }
};
  
/// FriendClassDecl - Represents the declaration of a friend class.
/// For example:
/// 
/// @code
/// class X {
///   friend class Y;
/// };
/// @endcode
class FriendClassDecl : public Decl {
  // The friended type.  In C++0x, this can be an arbitrary type,
  // which we simply ignore if it's not a record type.
  QualType FriendType;

  // Location of the 'friend' specifier.
  SourceLocation FriendLoc;

  FriendClassDecl(DeclContext *DC, SourceLocation L,
                  QualType T, SourceLocation FriendL)
    : Decl(FriendClass, DC, L),
      FriendType(T),
      FriendLoc(FriendL)
  {}

public:
  static FriendClassDecl *Create(ASTContext &C, DeclContext *DC,
                                 SourceLocation L, QualType T,
                                 SourceLocation FriendL);

  QualType getFriendType() const {
    return FriendType;
  }

  SourceLocation getFriendLoc() const {
    return FriendLoc;
  }

  // Implement isa/cast/dyncast/etc.
  static bool classof(const Decl *D) { 
    return D->getKind() == FriendClass;
  }
  static bool classof(const FriendClassDecl *D) { return true; }
};
  
/// LinkageSpecDecl - This represents a linkage specification.  For example:
///   extern "C" void foo();
///
class LinkageSpecDecl : public Decl, public DeclContext {
public:
  /// LanguageIDs - Used to represent the language in a linkage
  /// specification.  The values are part of the serialization abi for
  /// ASTs and cannot be changed without altering that abi.  To help
  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
  /// from the dwarf standard.
  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
private:
  /// Language - The language for this linkage specification.
  LanguageIDs Language;

  /// HadBraces - Whether this linkage specification had curly braces or not.
  bool HadBraces : 1;

  LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang, 
                  bool Braces)
    : Decl(LinkageSpec, DC, L), 
      DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }

public:
  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 
                                 SourceLocation L, LanguageIDs Lang, 
                                 bool Braces);

  LanguageIDs getLanguage() const { return Language; }

  /// hasBraces - Determines whether this linkage specification had
  /// braces in its syntactic form.
  bool hasBraces() const { return HadBraces; }

  static bool classof(const Decl *D) {
    return D->getKind() == LinkageSpec;
  }
  static bool classof(const LinkageSpecDecl *D) { return true; }
  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
  }
  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
  }
};

/// UsingDirectiveDecl - Represents C++ using-directive. For example:
///
///    using namespace std;
///
// NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
// artificial name, for all using-directives in order to store
// them in DeclContext effectively.
class UsingDirectiveDecl : public NamedDecl {

  /// SourceLocation - Location of 'namespace' token.
  SourceLocation NamespaceLoc;

  /// \brief The source range that covers the nested-name-specifier
  /// preceding the namespace name.
  SourceRange QualifierRange;

  /// \brief The nested-name-specifier that precedes the namespace
  /// name, if any.
  NestedNameSpecifier *Qualifier;

  /// IdentLoc - Location of nominated namespace-name identifier.
  // FIXME: We don't store location of scope specifier.
  SourceLocation IdentLoc;

  /// NominatedNamespace - Namespace nominated by using-directive.
  NamespaceDecl *NominatedNamespace;

  /// Enclosing context containing both using-directive and nomintated
  /// namespace.
  DeclContext *CommonAncestor;

  /// getUsingDirectiveName - Returns special DeclarationName used by
  /// using-directives. This is only used by DeclContext for storing
  /// UsingDirectiveDecls in its lookup structure.
  static DeclarationName getName() {
    return DeclarationName::getUsingDirectiveName();
  }

  UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
                     SourceLocation NamespcLoc,
                     SourceRange QualifierRange,
                     NestedNameSpecifier *Qualifier,
                     SourceLocation IdentLoc,
                     NamespaceDecl *Nominated,
                     DeclContext *CommonAncestor)
    : NamedDecl(Decl::UsingDirective, DC, L, getName()),
      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 
      Qualifier(Qualifier), IdentLoc(IdentLoc), 
      NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0),
      CommonAncestor(CommonAncestor) {
  }

public:
  /// \brief Retrieve the source range of the nested-name-specifier
  /// that qualifiers the namespace name.
  SourceRange getQualifierRange() const { return QualifierRange; }

  /// \brief Retrieve the nested-name-specifier that qualifies the
  /// name of the namespace.
  NestedNameSpecifier *getQualifier() const { return Qualifier; }

  /// getNominatedNamespace - Returns namespace nominated by using-directive.
  NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; }

  const NamespaceDecl *getNominatedNamespace() const {
    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
  }

  /// getCommonAncestor - returns common ancestor context of using-directive,
  /// and nominated by it namespace.
  DeclContext *getCommonAncestor() { return CommonAncestor; }
  const DeclContext *getCommonAncestor() const { return CommonAncestor; }

  /// getNamespaceKeyLocation - Returns location of namespace keyword.
  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }

  /// getIdentLocation - Returns location of identifier.
  SourceLocation getIdentLocation() const { return IdentLoc; }

  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
                                    SourceLocation L,
                                    SourceLocation NamespaceLoc,
                                    SourceRange QualifierRange,
                                    NestedNameSpecifier *Qualifier,
                                    SourceLocation IdentLoc,
                                    NamespaceDecl *Nominated,
                                    DeclContext *CommonAncestor);

  static bool classof(const Decl *D) {
    return D->getKind() == Decl::UsingDirective;
  }
  static bool classof(const UsingDirectiveDecl *D) { return true; }

  // Friend for getUsingDirectiveName.
  friend class DeclContext;
};

/// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
///
/// @code
/// namespace Foo = Bar;
/// @endcode
class NamespaceAliasDecl : public NamedDecl {
  SourceLocation AliasLoc;

  /// \brief The source range that covers the nested-name-specifier
  /// preceding the namespace name.
  SourceRange QualifierRange;

  /// \brief The nested-name-specifier that precedes the namespace
  /// name, if any.
  NestedNameSpecifier *Qualifier;
  
  /// IdentLoc - Location of namespace identifier.
  SourceLocation IdentLoc;
  
  /// Namespace - The Decl that this alias points to. Can either be a 
  /// NamespaceDecl or a NamespaceAliasDecl.
  NamedDecl *Namespace;
  
  NamespaceAliasDecl(DeclContext *DC, SourceLocation L, 
                     SourceLocation AliasLoc, IdentifierInfo *Alias, 
                     SourceRange QualifierRange,
                     NestedNameSpecifier *Qualifier,
                     SourceLocation IdentLoc, NamedDecl *Namespace)
    : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), 
      QualifierRange(QualifierRange), Qualifier(Qualifier),
      IdentLoc(IdentLoc), Namespace(Namespace) { }

public:
  /// \brief Retrieve the source range of the nested-name-specifier
  /// that qualifiers the namespace name.
  SourceRange getQualifierRange() const { return QualifierRange; }

  /// \brief Retrieve the nested-name-specifier that qualifies the
  /// name of the namespace.
  NestedNameSpecifier *getQualifier() const { return Qualifier; }

  NamespaceDecl *getNamespace() {
    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
      return AD->getNamespace();

    return cast<NamespaceDecl>(Namespace);
  }
  
  const NamespaceDecl *getNamespace() const {
    return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
  }

  /// \brief Retrieve the namespace that this alias refers to, which
  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
  NamedDecl *getAliasedNamespace() const { return Namespace; }

  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 
                                    SourceLocation L, SourceLocation AliasLoc, 
                                    IdentifierInfo *Alias, 
                                    SourceRange QualifierRange,
                                    NestedNameSpecifier *Qualifier,
                                    SourceLocation IdentLoc, 
                                    NamedDecl *Namespace);
  
  static bool classof(const Decl *D) {
    return D->getKind() == Decl::NamespaceAlias;
  }
  static bool classof(const NamespaceAliasDecl *D) { return true; }
};

/// UsingDecl - Represents a C++ using-declaration. For example:
///    using someNameSpace::someIdentifier;
class UsingDecl : public NamedDecl {

  /// \brief The source range that covers the nested-name-specifier
  /// preceding the declaration name.
  SourceRange NestedNameRange;
  /// \brief The source location of the target declaration name.
  SourceLocation TargetNameLocation;
  /// \brief The source location of the "using" location itself.
  SourceLocation UsingLocation;
  /// \brief Target declaration.
  NamedDecl* TargetDecl;
  /// \brief Target declaration.
  NestedNameSpecifier* TargetNestedNameDecl;

  // Had 'typename' keyword.
  bool IsTypeName;

  UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
            SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target,
            NestedNameSpecifier* TargetNNS, bool IsTypeNameArg)
    : NamedDecl(Decl::Using, DC, L, Target->getDeclName()),
      NestedNameRange(NNR), TargetNameLocation(TargetNL),
      UsingLocation(UL), TargetDecl(Target),
      TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) { 
    this->IdentifierNamespace = TargetDecl->getIdentifierNamespace();
  }

public:
  /// \brief Returns the source range that covers the nested-name-specifier
  /// preceding the namespace name.
  SourceRange getNestedNameRange() { return NestedNameRange; }
  
  /// \brief Returns the source location of the target declaration name.
  SourceLocation getTargetNameLocation() { return TargetNameLocation; }
  
  /// \brief Returns the source location of the "using" location itself.
  SourceLocation getUsingLocation() { return UsingLocation; }
  
  /// \brief getTargetDecl - Returns target specified by using-decl.
  NamedDecl *getTargetDecl() { return TargetDecl; }
  const NamedDecl *getTargetDecl() const { return TargetDecl; }
  
  /// \brief Get target nested name declaration.
  NestedNameSpecifier* getTargetNestedNameDecl() { 
    return TargetNestedNameDecl; 
  }
  
  /// isTypeName - Return true if using decl had 'typename'.
  bool isTypeName() const { return IsTypeName; }

  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
      SourceLocation L, SourceRange NNR, SourceLocation TargetNL,
      SourceLocation UL, NamedDecl* Target,
      NestedNameSpecifier* TargetNNS, bool IsTypeNameArg);

  static bool classof(const Decl *D) {
    return D->getKind() == Decl::Using;
  }
  static bool classof(const UsingDecl *D) { return true; }
};
  
/// StaticAssertDecl - Represents a C++0x static_assert declaration.
class StaticAssertDecl : public Decl {
  Expr *AssertExpr;
  StringLiteral *Message;

  StaticAssertDecl(DeclContext *DC, SourceLocation L, 
                   Expr *assertexpr, StringLiteral *message)
  : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
  
public:
  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
                                  SourceLocation L, Expr *AssertExpr,
                                  StringLiteral *Message);
  
  Expr *getAssertExpr() { return AssertExpr; }
  const Expr *getAssertExpr() const { return AssertExpr; }
  
  StringLiteral *getMessage() { return Message; }
  const StringLiteral *getMessage() const { return Message; }
  
  virtual ~StaticAssertDecl();
  virtual void Destroy(ASTContext& C);

  static bool classof(const Decl *D) {
    return D->getKind() == Decl::StaticAssert;
  }
  static bool classof(StaticAssertDecl *D) { return true; }
};

/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
/// into a diagnostic with <<.
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                    AccessSpecifier AS);
  
} // end namespace clang

#endif