From 0d4f0683be2cadc04de867f8e1e0a95ac9530a94 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 11 Aug 2014 00:37:19 +0200 Subject: [PATCH] Make Language::classLookup() and enumLookup() static. This will allow to reuse them in the code that doesn't have access to a Language object, such as DoxygenTranslator implementation. These methods didn't really use any of Language object non-static fields anyhow, the only one they did use (classtypes or enumtypes, respectively), was only used for caching and can just as well be made local to the function itself as long as we use other global variables anyhow. --- Source/Modules/lang.cxx | 18 +++++++++++------- Source/Modules/swigmod.h | 6 ++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 824018c4a..aa0f7d949 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -318,8 +318,6 @@ none_comparison(NewString("$arg != 0")), director_ctor_code(NewString("")), director_prot_ctor_code(0), symtabs(NewHash()), -classtypes(NewHash()), -enumtypes(NewHash()), overloading(0), multiinput(0), cplus_runtime(0), @@ -346,8 +344,6 @@ directors(0) { Language::~Language() { Delete(symtabs); - Delete(classtypes); - Delete(enumtypes); Delete(director_ctor_code); Delete(none_comparison); this_ = 0; @@ -3209,11 +3205,13 @@ Node *Language::symbolLookup(String *s, const_String_or_char_ptr scope) { * Tries to locate a class from a type definition * ----------------------------------------------------------------------------- */ -Node *Language::classLookup(const SwigType *s) const { +Node *Language::classLookup(const SwigType *s) { + static Hash *classtypes = 0; + Node *n = 0; /* Look in hash of cached values */ - n = Getattr(classtypes, s); + n = classtypes ? Getattr(classtypes, s) : 0; if (!n) { Symtab *stab = 0; SwigType *ty1 = SwigType_typedef_resolve_all(s); @@ -3268,6 +3266,8 @@ Node *Language::classLookup(const SwigType *s) const { } if (acceptable_prefix) { SwigType *cs = Copy(s); + if (!classtypes) + classtypes = NewHash(); Setattr(classtypes, cs, n); Delete(cs); } else { @@ -3294,10 +3294,12 @@ Node *Language::classLookup(const SwigType *s) const { * ----------------------------------------------------------------------------- */ Node *Language::enumLookup(SwigType *s) { + static Hash *enumtypes = 0; + Node *n = 0; /* Look in hash of cached values */ - n = Getattr(enumtypes, s); + n = enumtypes ? Getattr(enumtypes, s) : 0; if (!n) { Symtab *stab = 0; SwigType *lt = SwigType_ltype(s); @@ -3338,6 +3340,8 @@ Node *Language::enumLookup(SwigType *s) { if (n) { /* Found a match. Look at the prefix. We only allow simple types. */ if (Len(prefix) == 0) { /* Simple type */ + if (!enumtypes) + enumtypes = NewHash(); Setattr(enumtypes, Copy(s), n); } else { n = 0; diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 2922a6057..84a15b0d1 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -225,8 +225,8 @@ public: virtual Hash* symbolAddScope(const_String_or_char_ptr scope); virtual Hash* symbolScopeLookup(const_String_or_char_ptr scope); virtual Hash* symbolScopePseudoSymbolLookup(const_String_or_char_ptr scope); - virtual Node *classLookup(const SwigType *s) const; /* Class lookup */ - virtual Node *enumLookup(SwigType *s); /* Enum lookup */ + static Node *classLookup(const SwigType *s); /* Class lookup */ + static Node *enumLookup(SwigType *s); /* Enum lookup */ virtual int abstractClassTest(Node *n); /* Is class really abstract? */ virtual int is_assignable(Node *n); /* Is variable assignable? */ virtual String *runtimeCode(); /* returns the language specific runtime code */ @@ -349,8 +349,6 @@ protected: private: Hash *symtabs; /* symbol tables */ - Hash *classtypes; - Hash *enumtypes; int overloading; int multiinput; int cplus_runtime;