diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/Expr.h | 70 | ||||
| -rw-r--r-- | clang/include/clang/AST/Stmt.h | 10 | ||||
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 20 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTReaderStmt.cpp | 14 | 
4 files changed, 62 insertions, 52 deletions
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index f006f0ec6df..9a8ed5ddd4e 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -669,41 +669,43 @@ struct ExplicitTemplateArgumentList {    static std::size_t sizeFor(unsigned NumTemplateArgs);    static std::size_t sizeFor(const TemplateArgumentListInfo &List);  }; -   -/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, -/// enum, etc. + +/// \brief A reference to a declared variable, function, enum, etc. +/// [C99 6.5.1p2] +/// +/// This encodes all the information about how a declaration is referenced +/// within an expression. +/// +/// There are several optional constructs attached to DeclRefExprs only when +/// they apply in order to conserve memory. These are laid out past the end of +/// the object, and flags in the DeclRefExprBitfield track whether they exist: +/// +///   DeclRefExprBits.HasQualifier: +///       Specifies when this declaration reference expression has a C++ +///       nested-name-specifier. +///   DeclRefExprBits.HasExplicitTemplateArgs: +///       Specifies when this declaration reference expression has an explicit +///       C++ template argument list.  class DeclRefExpr : public Expr { -  enum { -    // Flag on DecoratedD that specifies when this declaration reference  -    // expression has a C++ nested-name-specifier. -    HasQualifierFlag = 0x01, -    // Flag on DecoratedD that specifies when this declaration reference  -    // expression has an explicit C++ template argument list. -    HasExplicitTemplateArgumentListFlag = 0x02 -  }; -   -  // DecoratedD - The declaration that we are referencing, plus two bits to  -  // indicate whether (1) the declaration's name was explicitly qualified and -  // (2) the declaration's name was followed by an explicit template  -  // argument list. -  llvm::PointerIntPair<ValueDecl *, 2> DecoratedD; +  /// \brief The declaration that we are referencing. +  ValueDecl *D; -  // Loc - The location of the declaration name itself. +  /// \brief The location of the declaration name itself.    SourceLocation Loc; -  /// DNLoc - Provides source/type location info for the -  /// declaration name embedded in DecoratedD. +  /// \brief Provides source/type location info for the declaration name +  /// embedded in D.    DeclarationNameLoc DNLoc;    /// \brief Retrieve the qualifier that preceded the declaration name, if any.    NameQualifier *getNameQualifier() { -    if ((DecoratedD.getInt() & HasQualifierFlag) == 0) +    if (!hasQualifier())        return 0; -     +      return reinterpret_cast<NameQualifier *> (this + 1);    } -   -  /// \brief Retrieve the qualifier that preceded the member name, if any. + +  /// \brief Retrieve the qualifier that preceded the declaration name, if any.    const NameQualifier *getNameQualifier() const {      return const_cast<DeclRefExpr *>(this)->getNameQualifier();    } @@ -727,9 +729,11 @@ class DeclRefExpr : public Expr {    void computeDependence();  public: -  DeclRefExpr(ValueDecl *d, QualType t, ExprValueKind VK, SourceLocation l) : -    Expr(DeclRefExprClass, t, VK, OK_Ordinary, false, false, false), -    DecoratedD(d, 0), Loc(l) { +  DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L) +    : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false), +      D(D), Loc(L) { +    DeclRefExprBits.HasQualifier = 0; +    DeclRefExprBits.HasExplicitTemplateArgs = 0;      computeDependence();    } @@ -753,9 +757,9 @@ public:                                    bool HasExplicitTemplateArgs,                                    unsigned NumTemplateArgs); -  ValueDecl *getDecl() { return DecoratedD.getPointer(); } -  const ValueDecl *getDecl() const { return DecoratedD.getPointer(); } -  void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); } +  ValueDecl *getDecl() { return D; } +  const ValueDecl *getDecl() const { return D; } +  void setDecl(ValueDecl *NewD) { D = NewD; }    DeclarationNameInfo getNameInfo() const {      return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); @@ -767,7 +771,7 @@ public:    /// \brief Determine whether this declaration reference was preceded by a    /// C++ nested-name-specifier, e.g., \c N::foo. -  bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } +  bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }    /// \brief If the name was qualified, retrieves the nested-name-specifier     /// that precedes the name. Otherwise, returns NULL. @@ -788,7 +792,7 @@ public:    }    bool hasExplicitTemplateArgs() const { -    return (DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag); +    return DeclRefExprBits.HasExplicitTemplateArgs;    }    /// \brief Retrieve the explicit template argument list that followed the @@ -796,7 +800,7 @@ public:    ExplicitTemplateArgumentList &getExplicitTemplateArgs() {      assert(hasExplicitTemplateArgs()); -    if ((DecoratedD.getInt() & HasQualifierFlag) == 0) +    if (!hasQualifier())        return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);      return *reinterpret_cast<ExplicitTemplateArgumentList *>( diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index e3301c513a7..903096e137c 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -158,6 +158,15 @@ protected:    };    enum { NumExprBits = 15 }; +  class DeclRefExprBitfields { +    friend class DeclRefExpr; +    friend class ASTStmtReader; // deserialization +    unsigned : NumExprBits; + +    unsigned HasQualifier : 1; +    unsigned HasExplicitTemplateArgs : 1; +  }; +    class CastExprBitfields {      friend class CastExpr;      unsigned : NumExprBits; @@ -180,6 +189,7 @@ protected:      StmtBitfields StmtBits;      CompoundStmtBitfields CompoundStmtBits;      ExprBitfields ExprBits; +    DeclRefExprBitfields DeclRefExprBits;      CastExprBitfields CastExprBits;      CallExprBitfields CallExprBits;    }; diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 2a5917c4594..cd5a63aab51 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -279,17 +279,18 @@ DeclRefExpr::DeclRefExpr(NestedNameSpecifierLoc QualifierLoc,                           const TemplateArgumentListInfo *TemplateArgs,                           QualType T, ExprValueKind VK)    : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false), -    DecoratedD(D, -               (QualifierLoc? HasQualifierFlag : 0) | -               (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), -    Loc(NameLoc) { +    D(D), Loc(NameLoc) { +  DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0;    if (QualifierLoc) { +    DeclRefExprBits.HasQualifier = 1;      NameQualifier *NQ = getNameQualifier();      NQ->QualifierLoc = QualifierLoc;    } -       -  if (TemplateArgs) + +  DeclRefExprBits.HasExplicitTemplateArgs = TemplateArgs ? 1 : 0; +  if (TemplateArgs) {      getExplicitTemplateArgs().initializeFrom(*TemplateArgs); +  }    computeDependence();  } @@ -299,15 +300,14 @@ DeclRefExpr::DeclRefExpr(NestedNameSpecifierLoc QualifierLoc,                           const TemplateArgumentListInfo *TemplateArgs,                           QualType T, ExprValueKind VK)    : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false), -    DecoratedD(D, -               (QualifierLoc? HasQualifierFlag : 0) | -               (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), -    Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { +    D(D), Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { +  DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0;    if (QualifierLoc) {      NameQualifier *NQ = getNameQualifier();      NQ->QualifierLoc = QualifierLoc;    } +  DeclRefExprBits.HasExplicitTemplateArgs = TemplateArgs ? 1 : 0;    if (TemplateArgs)      getExplicitTemplateArgs().initializeFrom(*TemplateArgs); diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index 83b3907f581..f0b5abaf3bf 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -425,21 +425,17 @@ void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {  void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {    VisitExpr(E); -  bool HasQualifier = Record[Idx++]; -  bool HasExplicitTemplateArgs = Record[Idx++]; +  E->DeclRefExprBits.HasQualifier = Record[Idx++]; +  E->DeclRefExprBits.HasExplicitTemplateArgs = Record[Idx++];    unsigned NumTemplateArgs = 0; -  if (HasExplicitTemplateArgs) +  if (E->hasExplicitTemplateArgs())      NumTemplateArgs = Record[Idx++]; -  E->DecoratedD.setInt((HasQualifier? DeclRefExpr::HasQualifierFlag : 0) | -      (HasExplicitTemplateArgs  -         ? DeclRefExpr::HasExplicitTemplateArgumentListFlag : 0)); -   -  if (HasQualifier) +  if (E->hasQualifier())      E->getNameQualifier()->QualifierLoc        = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); -  if (HasExplicitTemplateArgs) +  if (E->hasExplicitTemplateArgs())      ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),                                       NumTemplateArgs);  | 

