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/c-lang.c | |
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/c-lang.c')
-rw-r--r-- | gdb/c-lang.c | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/gdb/c-lang.c b/gdb/c-lang.c index e549c5c..4dac718 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -885,7 +885,9 @@ static const char *c_extensions[] = ".c", NULL }; -extern const struct language_defn c_language_defn = +/* Constant data that describes the C language. */ + +extern const struct language_data c_language_data = { "c", /* Language name */ "C", @@ -934,6 +936,20 @@ extern const struct language_defn c_language_defn = "{...}" /* la_struct_too_deep_ellipsis */ }; +/* Class representing the C language. */ + +class c_language : public language_defn +{ +public: + c_language () + : language_defn (language_c, c_language_data) + { /* Nothing. */ } +}; + +/* Single instance of the C language class. */ + +static c_language c_language_defn; + enum cplus_primitive_types { cplus_primitive_type_int, cplus_primitive_type_long, @@ -1030,7 +1046,9 @@ static const char *cplus_extensions[] = ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", NULL }; -extern const struct language_defn cplus_language_defn = +/* Constant data that describes the C++ language. */ + +extern const struct language_data cplus_language_data = { "c++", /* Language name */ "C++", @@ -1079,12 +1097,28 @@ extern const struct language_defn cplus_language_defn = "{...}" /* la_struct_too_deep_ellipsis */ }; +/* A class for the C++ language. */ + +class cplus_language : public language_defn +{ +public: + cplus_language () + : language_defn (language_cplus, cplus_language_data) + { /* Nothing. */ } +}; + +/* The single instance of the C++ language class. */ + +static cplus_language cplus_language_defn; + static const char *asm_extensions[] = { ".s", ".sx", ".S", NULL }; -extern const struct language_defn asm_language_defn = +/* Constant data that describes the ASM language. */ + +extern const struct language_data asm_language_data = { "asm", /* Language name */ "assembly", @@ -1133,12 +1167,25 @@ extern const struct language_defn asm_language_defn = "{...}" /* la_struct_too_deep_ellipsis */ }; +/* A class for the ASM language. */ + +class asm_language : public language_defn +{ +public: + asm_language () + : language_defn (language_asm, asm_language_data) + { /* Nothing. */ } +}; + +/* The single instance of the ASM language class. */ +static asm_language asm_language_defn; + /* The following language_defn does not represent a real language. It just provides a minimal support a-la-C that should allow users to do some simple operations when debugging applications that use a language currently not supported by GDB. */ -extern const struct language_defn minimal_language_defn = +extern const struct language_data minimal_language_data = { "minimal", /* Language name */ "Minimal", @@ -1186,3 +1233,16 @@ extern const struct language_defn minimal_language_defn = c_is_string_type_p, "{...}" /* la_struct_too_deep_ellipsis */ }; + +/* A class for the minimal language. */ + +class minimal_language : public language_defn +{ +public: + minimal_language () + : language_defn (language_minimal, minimal_language_data) + { /* Nothing. */ } +}; + +/* The single instance of the minimal language class. */ +static minimal_language minimal_language_defn; |