diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-05-01 12:16:58 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-06-02 13:53:10 +0100 |
commit | 0874fd075b2a519022259a3cc48e650dc1daeeab (patch) | |
tree | 7fb83a902b19cb5dc06632bb4da59e127735412d /gdb/language.h | |
parent | 621eacdfb42f9deba559ea0bada70f6ca2367f5f (diff) | |
download | gdb-0874fd075b2a519022259a3cc48e650dc1daeeab.zip gdb-0874fd075b2a519022259a3cc48e650dc1daeeab.tar.gz gdb-0874fd075b2a519022259a3cc48e650dc1daeeab.tar.bz2 |
gdb: Represent all languages as sub-classes of language_defn
This commit converts all languages to sub-classes of a language_defn
base class.
The motivation for this change is to make it easier to add new methods
onto languages without having to update all of the individual language
structures. In the future it might be possible to move more things,
like expression parsing, into the language class(es) for better
encapsulation, however I have no plans to tackle this in the short
term.
This commit sets up a strategy for transitioning from the current
language system, where each language is an instance of the
language_defn structure, to the class hierarchy system.
The plan is to rename the existing language_defn into language_data,
and make this a base class for the new language_defn class, something
like this:
struct language_data
{
... old language_defn fields here ...
};
struct language_defn : public language_data
{
language_defn (const language_data d)
: language_data (d)
{ .... }
};
Then each existing language, for example ada_language_defn can be
converted into an instance of language_data, and passed into the
constructor of a new language class, something like this:
language_data ada_language_data =
{
... old ada_language_defn values here ...
};
struct ada_language : public language_defn
{
ada_language (ada_language_data)
{ .... }
};
What this means is that immediately after the conversion nothing much
changes. Every language is now its own class, but all the old
language fields still exist and can be accessed in the same way.
In later commits I will convert function pointers from the old
language_defn structure into real class methods on language_defn, with
overrides on sub-classes where needed.
At this point I imagine that those fields of the old language_defn
structure that contained only data will probably remain as data fields
within the new language_data base structure, it is only the methods
that I plan to change initially.
I tweaked how we manage the list of languages a bit, each language is
now registered as it is created, and this resulted in a small number
of changes in language.c.
Most of the changes in the *-lang.c files are identical.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* gdb/ada-lang.c (ada_language_defn): Convert to...
(ada_language_data): ...this.
(class ada_language): New class.
(ada_language_defn): New static global.
* gdb/c-lang.c (c_language_defn): Convert to...
(c_language_data): ...this.
(class c_language): New class.
(c_language_defn): New static global.
(cplus_language_defn): Convert to...
(cplus_language_data): ...this.
(class cplus_language): New class.
(cplus_language_defn): New static global.
(asm_language_defn): Convert to...
(asm_language_data): ...this.
(class asm_language): New class.
(asm_language_defn): New static global.
(minimal_language_defn): Convert to...
(minimal_language_data): ...this.
(class minimal_language): New class.
(minimal_language_defn): New static global.
* gdb/d-lang.c (d_language_defn): Convert to...
(d_language_data): ...this.
(class d_language): New class.
(d_language_defn): New static global.
* gdb/f-lang.c (f_language_defn): Convert to...
(f_language_data): ...this.
(class f_language): New class.
(f_language_defn): New static global.
* gdb/go-lang.c (go_language_defn): Convert to...
(go_language_data): ...this.
(class go_language): New class.
(go_language_defn): New static global.
* gdb/language.c (unknown_language_defn): Remove declaration.
(current_language): Initialize to nullptr, real initialization is
moved to _initialize_language.
(languages): Delete global.
(language_defn::languages): Define.
(set_language_command): Use language_defn::languages.
(set_language): Likewise.
(range_error): Likewise.
(language_enum): Likewise.
(language_def): Likewise.
(add_set_language_command): Use language_def::languages for the
language list, and language_def to lookup language pointers.
(skip_language_trampoline): Use language_defn::languages.
(unknown_language_defn): Convert to...
(unknown_language_data): ...this.
(class unknown_language): New class.
(unknown_language_defn): New static global.
(auto_language_defn): Convert to...
(auto_language_data): ...this.
(class auto_language): New class.
(auto_language_defn): New static global.
(language_gdbarch_post_init): Use language_defn::languages.
(_initialize_language): Initialize current_language.
* gdb/language.h (struct language_defn): Rename to...
(struct language_data): ...this.
(struct language_defn): New.
(auto_language_defn): Delete.
(unknown_language_defn): Delete.
(minimal_language_defn): Delete.
(ada_language_defn): Delete.
(asm_language_defn): Delete.
(c_language_defn): Delete.
(cplus_language_defn): Delete.
(d_language_defn): Delete.
(f_language_defn): Delete.
(go_language_defn): Delete.
(m2_language_defn): Delete.
(objc_language_defn): Delete.
(opencl_language_defn): Delete.
(pascal_language_defn): Delete.
(rust_language_defn): Delete.
* gdb/m2-lang.c (m2_language_defn): Convert to...
(m2_language_data): ...this.
(class m2_language): New class.
(m2_language_defn): New static global.
* gdb/objc-lang.c (objc_language_defn): Convert to...
(objc_language_data): ...this.
(class objc_language): New class.
(objc_language_defn): New static global.
* gdb/opencl-lang.c (opencl_language_defn): Convert to...
(opencl_language_data): ...this.
(class opencl_language): New class.
(opencl_language_defn): New static global.
* gdb/p-lang.c (pascal_language_defn): Convert to...
(pascal_language_data): ...this.
(class pascal_language): New class.
(pascal_language_defn): New static global.
* gdb/rust-exp.y (rust_lex_tests): Use language_def to find
language pointer, update comment format.
* gdb/rust-lang.c (rust_language_defn): Convert to...
(rust_language_data): ...this.
(class rust_language): New class.
(rust_language_defn): New static global.
Diffstat (limited to 'gdb/language.h')
-rw-r--r-- | gdb/language.h | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/gdb/language.h b/gdb/language.h index e112a91..351ad49 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -169,9 +169,21 @@ struct language_pass_by_ref_info bool destructible = true; }; -/* Structure tying together assorted information about a language. */ +/* Structure tying together assorted information about a language. -struct language_defn + As we move over from the old structure based languages to a class + hierarchy of languages this structure will continue to contain a + mixture of both data and function pointers. + + Once the class hierarchy of languages in place the first task is to + remove the function pointers from this structure and convert them into + member functions on the different language classes. + + The current plan it to keep the constant data that describes a language + in this structure, and have each language pass in an instance of this + structure at construction time. */ + +struct language_data { /* Name of the language. */ @@ -471,6 +483,22 @@ struct language_defn }; +/* Base class from which all other language classes derive. */ + +struct language_defn : language_data +{ + language_defn (enum language lang, const language_data &init_data) + : language_data (init_data) + { + /* We should only ever create one instance of each language. */ + gdb_assert (languages[lang] == nullptr); + languages[lang] = this; + } + + /* List of all known languages. */ + static const struct language_defn *languages[nr_languages]; +}; + /* Pointer to the language_defn for our current language. This pointer always points to *some* valid struct; it can be used without checking it for validity. @@ -681,25 +709,6 @@ extern bool default_symbol_name_matcher symbol_name_matcher_ftype *get_symbol_name_matcher (const language_defn *lang, const lookup_name_info &lookup_name); -/* The languages supported by GDB. */ - -extern const struct language_defn auto_language_defn; -extern const struct language_defn unknown_language_defn; -extern const struct language_defn minimal_language_defn; - -extern const struct language_defn ada_language_defn; -extern const struct language_defn asm_language_defn; -extern const struct language_defn c_language_defn; -extern const struct language_defn cplus_language_defn; -extern const struct language_defn d_language_defn; -extern const struct language_defn f_language_defn; -extern const struct language_defn go_language_defn; -extern const struct language_defn m2_language_defn; -extern const struct language_defn objc_language_defn; -extern const struct language_defn opencl_language_defn; -extern const struct language_defn pascal_language_defn; -extern const struct language_defn rust_language_defn; - /* Save the current language and restore it upon destruction. */ class scoped_restore_current_language |