John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame^] | 1 | //===--- TemplateBase.cpp - Common template AST class implementation ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements common classes used throughout C++ template |
| 11 | // representations. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/ADT/FoldingSet.h" |
| 16 | #include "clang/AST/TemplateBase.h" |
| 17 | #include "clang/AST/DeclBase.h" |
| 18 | #include "clang/AST/Expr.h" |
| 19 | |
| 20 | using namespace clang; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // TemplateArgument Implementation |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | TemplateArgument::TemplateArgument(Expr *E) : Kind(Expression) { |
| 27 | TypeOrValue = reinterpret_cast<uintptr_t>(E); |
| 28 | StartLoc = E->getSourceRange().getBegin(); |
| 29 | } |
| 30 | |
| 31 | /// \brief Construct a template argument pack. |
| 32 | void TemplateArgument::setArgumentPack(TemplateArgument *args, unsigned NumArgs, |
| 33 | bool CopyArgs) { |
| 34 | assert(isNull() && "Must call setArgumentPack on a null argument"); |
| 35 | |
| 36 | Kind = Pack; |
| 37 | Args.NumArgs = NumArgs; |
| 38 | Args.CopyArgs = CopyArgs; |
| 39 | if (!Args.CopyArgs) { |
| 40 | Args.Args = args; |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | // FIXME: Allocate in ASTContext |
| 45 | Args.Args = new TemplateArgument[NumArgs]; |
| 46 | for (unsigned I = 0; I != Args.NumArgs; ++I) |
| 47 | Args.Args[I] = args[I]; |
| 48 | } |
| 49 | |
| 50 | void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID, |
| 51 | ASTContext &Context) const { |
| 52 | ID.AddInteger(Kind); |
| 53 | switch (Kind) { |
| 54 | case Null: |
| 55 | break; |
| 56 | |
| 57 | case Type: |
| 58 | getAsType().Profile(ID); |
| 59 | break; |
| 60 | |
| 61 | case Declaration: |
| 62 | ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : 0); |
| 63 | break; |
| 64 | |
| 65 | case Integral: |
| 66 | getAsIntegral()->Profile(ID); |
| 67 | getIntegralType().Profile(ID); |
| 68 | break; |
| 69 | |
| 70 | case Expression: |
| 71 | getAsExpr()->Profile(ID, Context, true); |
| 72 | break; |
| 73 | |
| 74 | case Pack: |
| 75 | ID.AddInteger(Args.NumArgs); |
| 76 | for (unsigned I = 0; I != Args.NumArgs; ++I) |
| 77 | Args.Args[I].Profile(ID, Context); |
| 78 | } |
| 79 | } |