Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmDependsC.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmDependsC_h
13 #define cmDependsC_h
14
15 #include "cmDepends.h"
16 #include <cmsys/RegularExpression.hxx>
17 #include <queue>
18
19 /** \class cmDependsC
20  * \brief Dependency scanner for C and C++ object files.
21  */
22 class cmDependsC: public cmDepends
23 {
24 public:
25   /** Checking instances need to know the build directory name and the
26       relative path from the build directory to the target file.  */
27   cmDependsC();
28   cmDependsC(cmLocalGenerator* lg, const char* targetDir, const char* lang,
29              const std::map<std::string, DependencyVector>* validDeps);
30
31   /** Virtual destructor to cleanup subclasses properly.  */
32   virtual ~cmDependsC();
33
34 protected:
35   typedef std::vector<char> t_CharBuffer;
36
37   // Implement writing/checking methods required by superclass.
38   virtual bool WriteDependencies(const char *src,
39                                  const char *file,
40                                  std::ostream& makeDepends,
41                                  std::ostream& internalDepends);
42
43   // Method to scan a single file.
44   void Scan(std::istream& is, const char* directory,
45     const cmStdString& fullName);
46
47   // Regular expression to identify C preprocessor include directives.
48   cmsys::RegularExpression IncludeRegexLine;
49
50   // Regular expressions to choose which include files to scan
51   // recursively and which to complain about not finding.
52   cmsys::RegularExpression IncludeRegexScan;
53   cmsys::RegularExpression IncludeRegexComplain;
54   std::string IncludeRegexLineString;
55   std::string IncludeRegexScanString;
56   std::string IncludeRegexComplainString;
57
58   // Regex to transform #include lines.
59   std::string IncludeRegexTransformString;
60   cmsys::RegularExpression IncludeRegexTransform;
61   typedef std::map<cmStdString, cmStdString> TransformRulesType;
62   TransformRulesType TransformRules;
63   void SetupTransforms();
64   void ParseTransform(std::string const& xform);
65   void TransformLine(std::string& line);
66
67 public:
68   // Data structures for dependency graph walk.
69   struct UnscannedEntry
70   {
71     cmStdString FileName;
72     cmStdString QuotedLocation;
73   };
74
75   struct cmIncludeLines
76   {
77     cmIncludeLines(): Used(false) {}
78     std::vector<UnscannedEntry> UnscannedEntries;
79     bool Used;
80   };
81 protected:
82   const std::map<std::string, DependencyVector>* ValidDeps;
83   std::set<cmStdString> Encountered;
84   std::queue<UnscannedEntry> Unscanned;
85   t_CharBuffer Buffer;
86
87   std::map<cmStdString, cmIncludeLines *> FileCache;
88   std::map<cmStdString, cmStdString> HeaderLocationCache;
89
90   cmStdString CacheFileName;
91
92   void WriteCacheFile() const;
93   void ReadCacheFile();
94 private:
95   cmDependsC(cmDependsC const&); // Purposely not implemented.
96   void operator=(cmDependsC const&); // Purposely not implemented.
97 };
98
99 #endif