1 #ifndef PROJECT_TREE_BUILDER__RESOLVER__HPP
2 #define PROJECT_TREE_BUILDER__RESOLVER__HPP
3 
4 /* $Id: resolver.hpp 426194 2014-02-06 17:22:06Z gouriano $
5  * ===========================================================================
6  *
7  *                            PUBLIC DOMAIN NOTICE
8  *               National Center for Biotechnology Information
9  *
10  *  This software/database is a "United States Government Work" under the
11  *  terms of the United States Copyright Act.  It was written as part of
12  *  the author's official duties as a United States Government employee and
13  *  thus cannot be copyrighted.  This software/database is freely available
14  *  to the public for use. The National Library of Medicine and the U.S.
15  *  Government have not placed any restriction on its use or reproduction.
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  *  Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author:  Viatcheslav Gorelenkov
30  *
31  */
32 
33 #include "stl_msvc_usage.hpp"
34 #include "file_contents.hpp"
35 
36 #include <map>
37 #include <set>
38 #include <string>
39 
40 #include <corelib/ncbistre.hpp>
41 #include <corelib/ncbienv.hpp>
42 
43 
44 BEGIN_NCBI_SCOPE
45 
46 
47 class CSymResolver;
48 class CExpansionRule
49 {
50 public:
51     enum EExpRule {
52         eNoop,
53         eReplace,
54         ePattern
55     };
56 
57     CExpansionRule(void);
58     CExpansionRule(const string& textrule);
59     CExpansionRule(const CExpansionRule& other);
60     CExpansionRule& operator= (const CExpansionRule& other);
61 
62     void Reset();
63     void Init(const string& textrule,
64         CSymResolver* resolver=NULL,  const CSimpleMakeFileContents* data=NULL);
65 
66     string ApplyRule( const string& value) const;
67     void  ApplyRule( list<string>& value) const;
68 
69 private:
70     EExpRule m_Rule;
71     string m_Lvalue;
72     string m_Rvalue;
73 };
74 
75 class CSymResolver
76 {
77 public:
78     CSymResolver(void);
79     CSymResolver(const CSymResolver& resolver);
80     CSymResolver& operator= (const CSymResolver& resolver);
81     CSymResolver(const string& file_path);
82     ~CSymResolver(void);
83 
84     void Resolve(const string& define, list<string>* resolved_def);
85     void Resolve(const string& define, list<string>* resolved_def,
86                         const CSimpleMakeFileContents& data);
87 
88     CSymResolver& Append(const CSymResolver& src, bool warn_redef=false);
89 
90     static void LoadFrom(const string& file_path, CSymResolver* resolver);
91     void AddDefinition( const string& key, const string& value);
92     bool HasDefinition( const string& key) const;
GetValue(const string & key,string & value) const93     bool GetValue(const string& key, string& value) const
94     {
95         return m_Data.GetValue(key,value);
96     }
97 
98     bool IsEmpty(void) const;
99 
100     static bool   StripSuffix(string& libname, string* suffix=nullptr);
101     static bool   IsDefine   (const string& param);
102     static bool   HasDefine   (const string& param);
103     static string StripDefine(const string& define);
104     static string TrimDefine(const string& define);
105     string FilterDefine(const string& define, CExpansionRule& rule,
106                         const CSimpleMakeFileContents& data);
107 
108 private:
109     void Clear(void);
110     void SetFrom(const CSymResolver& resolver);
111 
112     CSimpleMakeFileContents m_Data;
113 
114     CSimpleMakeFileContents::TContents m_Cache;
115     set<string> m_Trusted;
116 };
117 
118 // Filter opt defines like $(SRC_C:.core_%)           to $(SRC_C).
119 // or $(OBJMGR_LIBS:dbapi_driver=dbapi_driver-static) to $(OBJMGR_LIBS)
120 string FilterDefine(const string& define);
121 
122 
123 END_NCBI_SCOPE
124 
125 #endif //PROJECT_TREE_BUILDER__RESOLVER__HPP
126