[PATCH] Private Headers for Modules

Lawrence Crowl crowl at google.com
Wed Mar 27 20:30:19 PDT 2013


Hi doug.gregor,

This patch adds new private headers to the module map.  Private
headers may be included from within the module, but not from outside
the module.

The patch does not provide any symbol export control, only inclusion
control.  This capability enables a small step towards limiting
unintended use of a module/library.

Changes are:

Add a list of PrivateHeaders to class Module.  Private headers will
appear in both this list and the main Headers list.

   Modify Module::print to print the new field.

   Modify the ASTReader/ASTWriter to handle PrivateHeaders.

   Concern: I am pretty sure I haven't quite gotten streaming right.

In ModuleMap, define an enum that describes the role of the header:
normal, excluded, or private.

   Modify ModuleMap::addHeader to take that enum rather than a
   boolean, and to also put the header on the PrivateHeaders list
   when the role is private.

   Concern: I have not modified KnownHeader to understand
   PrivateHeaders.  It wasn't necessary to this point, but I think
   doing so is likely to improve performance.  Thoughts?

In ModuleMap, add syntax for private headers.  This syntax is the
same as excluded headers, but substituting the token "private"
instead of "exclude".

   Add a new MMToken "private".

   Change the parameters of parseHeaderDecl from two mutually
   exclusive SourceLocations to a the leading token and the source
   location of that token.  Modify callers to match.  Some checking
   need not happen as a result.  Infer the header role from the
   leading token.

In PPDirectives, check that the module of the including file matches
the module of the included file.

   Modify Preprocessor::LookupFile to track the SourceLocation of a
   filename through its parameters to the diagnostic.  Modify callers
   to match.

Add new module tests for private headers.  These are pretty minimal.

http://llvm-reviews.chandlerc.com/D584

Files:
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Basic/Module.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/Pragma.cpp
  lib/Lex/ModuleMap.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/Modules/Inputs/private2/common.h
  test/Modules/Inputs/private1/private.h
  test/Modules/Inputs/private1/module.map
  test/Modules/Inputs/private1/public.h
  test/Modules/private1.cpp
  test/Modules/private2.cpp
  test/Modules/private3.cpp
  include/clang/Serialization/ASTBitCodes.h
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Basic/Module.h
  include/clang/Lex/ModuleMap.h
  include/clang/Lex/Preprocessor.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D584.1.patch
Type: text/x-patch
Size: 20946 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130327/0e08168a/attachment.bin>


More information about the cfe-commits mailing list