[cfe-commits] r84267 - in /cfe/trunk: include/clang-c/Index.h include/clang/AST/DeclBase.h include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp test/Index/c-index-pch.c tools/CIndex/CIndex.cpp tools/CIndex/CIndex.exports tools/c-index-test/c-index-test.c

Douglas Gregor dgregor at apple.com
Tue Nov 3 18:20:09 PST 2009


On Oct 16, 2009, at 1:10 PM, Fariborz Jahanian wrote:

>
> On Oct 16, 2009, at 1:01 PM, Douglas Gregor wrote:
>
>> Author: dgregor
>> Date: Fri Oct 16 15:01:17 2009
>> New Revision: 84267
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=84267&view=rev
>> Log:
>> Keep track of whether declararions were loaded from a precompiled
>> header or not via a new "PCHLevel" field in Decl. We currently use
>> this information to help CIndex filter out declarations that came  
>> from
>> a precompiled header (rather than from an AST file). Further down the
>> road, it can be used to help implement multi-level precompiled
>> headers.
>>
>>
>> Modified:
>>   cfe/trunk/include/clang-c/Index.h
>>   cfe/trunk/include/clang/AST/DeclBase.h
>>   cfe/trunk/include/clang/Frontend/ASTUnit.h
>>   cfe/trunk/lib/Frontend/ASTUnit.cpp
>>   cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
>>   cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
>>   cfe/trunk/test/Index/c-index-pch.c
>>   cfe/trunk/tools/CIndex/CIndex.cpp
>>   cfe/trunk/tools/CIndex/CIndex.exports
>>   cfe/trunk/tools/c-index-test/c-index-test.c
>>
>> Modified: cfe/trunk/include/clang-c/Index.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=84267&r1=84266&r2=84267&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> = 
>> =====================================================================
>> --- cfe/trunk/include/clang-c/Index.h (original)
>> +++ cfe/trunk/include/clang-c/Index.h Fri Oct 16 15:01:17 2009
>> @@ -117,6 +117,17 @@
>> );
>> void clang_disposeTranslationUnit(CXTranslationUnit);
>>
>> +/**
>> + * \brief Indicate to Clang that it should only enumerate "local"  
>> declarations
>> + * when loading any new translation units.
>> + *
>> + * A "local" declaration is one that belongs in the translation  
>> unit itself and
>> + * not in a precompiled header that was used by the translation  
>> unit.
>> + *
>> + * FIXME: Remove this hook.
>> + */
>> +void clang_wantOnlyLocalDeclarations(CXIndex);
>> +
>> /*
>>   Usage: clang_loadTranslationUnit(). Will load the toplevel  
>> declarations
>>   within a translation unit, issuing a 'callback' for each one.
>>
>> Modified: cfe/trunk/include/clang/AST/DeclBase.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=84267&r1=84266&r2=84267&view=diff
>>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/include/clang/AST/DeclBase.h (original)
>> +++ cfe/trunk/include/clang/AST/DeclBase.h Fri Oct 16 15:01:17 2009
>> @@ -166,6 +166,15 @@
>>  bool Used : 1;
>>
>> protected:
>> +  /// Access - Used by C++ decls for the access specifier.
>> +  // NOTE: VC++ treats enums as signed, avoid using the  
>> AccessSpecifier enum
>> +  unsigned Access : 2;
>> +  friend class CXXClassMemberWrapper;
>> +
>> +  // PCHLevel - the "level" of precompiled header/AST file from  
>> which this
>> +  // declaration was built.
>> +  unsigned PCHLevel : 2;
>> +
>>  /// IdentifierNamespace - This specifies what IDNS_* namespace  
>> this lives in.
>>  unsigned IdentifierNamespace : 16;
>>
>> @@ -177,16 +186,13 @@
>> #endif
>>
>> protected:
>> -  /// Access - Used by C++ decls for the access specifier.
>> -  // NOTE: VC++ treats enums as signed, avoid using the  
>> AccessSpecifier enum
>> -  unsigned Access : 2;
>> -  friend class CXXClassMemberWrapper;
>>
>>  Decl(Kind DK, DeclContext *DC, SourceLocation L)
>>    : NextDeclInContext(0), DeclCtx(DC),
>>      Loc(L), DeclKind(DK), InvalidDecl(0),
>>      HasAttrs(false), Implicit(false), Used(false),
>> -      IdentifierNamespace(getIdentifierNamespaceForKind(DK)),  
>> Access(AS_none) {
>> +      Access(AS_none), PCHLevel(0),
>> +      IdentifierNamespace(getIdentifierNamespaceForKind(DK)) {
>>    if (Decl::CollectingStats()) addDeclKind(DK);
>>  }
>>
>> @@ -274,6 +280,26 @@
>>  bool isUsed() const { return Used; }
>>  void setUsed(bool U = true) { Used = U; }
>>
>> +  /// \brief Retrieve the level of precompiled header from which  
>> this
>> +  /// declaration was generated.
>> +  ///
>> +  /// The PCH level of a declaration describes where the  
>> declaration originated
>> +  /// from. A PCH level of 0 indicates that the declaration was  
>> not from a
>> +  /// precompiled header. A PCH level of 1 indicates that the  
>> declaration was
>> +  /// from a top-level precompiled header; 2 indicates that the  
>> declaration
>> +  /// comes from a precompiled header on which the top-level  
>> precompiled header
>> +  /// depends, and so on.
>
> What do you mean by 'so on'? is it going to be 3 or more? Bit-field  
> length is 2.

I don't have a use case for more than 3. If we need more levels, we'll  
extend the bit-field.

   - Doug



More information about the cfe-commits mailing list