Internals: Make V3LanguageWords a singleton.

This commit is contained in:
Wilson Snyder 2019-07-13 08:57:42 -04:00
parent b3eab9d78a
commit d1ee6689c4
1 changed files with 152 additions and 149 deletions

View File

@ -30,25 +30,29 @@
class V3LanguageWords { class V3LanguageWords {
// List of common reserved keywords // List of common reserved keywords
private: private:
typedef std::map<string,string> KeywordMap; typedef std::map<string,string> KeywordMap;
KeywordMap m_kwdMap; // List of keywords, and what language applies struct Singleton {
KeywordMap s_kwdMap; // List of keywords, and what language applies
Singleton() { init(); }
void addKwd(const string& kwd, const string& why) { void addKwd(const string& kwd, const string& why) {
m_kwdMap.insert(make_pair(kwd, why)); s_kwdMap.insert(make_pair(kwd, why));
} }
void init();
};
public: public:
string isKeyword(const string& kwd) { // METHODS
KeywordMap::iterator it = m_kwdMap.find(kwd); static string isKeyword(const string& kwd) {
if (it == m_kwdMap.end()) return ""; KeywordMap::iterator it = s().s_kwdMap.find(kwd);
if (it == s().s_kwdMap.end()) return "";
return it->second; return it->second;
} }
private:
static Singleton& s() { static Singleton s_s; return s_s; }
};
public: inline void V3LanguageWords::Singleton::init() {
V3LanguageWords() {
// C++ keywords // C++ keywords
// C++
addKwd("NULL", "C++ common word"); addKwd("NULL", "C++ common word");
addKwd("abort", "C++ common word"); addKwd("abort", "C++ common word");
addKwd("alignas", "C++11 keyword"); addKwd("alignas", "C++11 keyword");
@ -184,6 +188,5 @@ class V3LanguageWords {
addKwd("sensitive_neg", "SystemC common word"); addKwd("sensitive_neg", "SystemC common word");
addKwd("sensitive_pos", "SystemC common word"); addKwd("sensitive_pos", "SystemC common word");
} }
};
#endif // Guard #endif // Guard