p-lang.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /* Pascal language support definitions for GDB, the GNU debugger.
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef P_LANG_H
  15. #define P_LANG_H
  16. /* This file is derived from c-lang.h */
  17. struct value;
  18. struct parser_state;
  19. /* Determines if type TYPE is a pascal string type. Returns a positive
  20. value if the type is a known pascal string type. This function is used
  21. by p-valprint.c code to allow better string display. If it is a pascal
  22. string type, then it also sets info needed to get the length and the
  23. data of the string length_pos, length_size and string_pos are given in
  24. bytes. char_size gives the element size in bytes. FIXME: if the
  25. position or the size of these fields are not multiple of TARGET_CHAR_BIT
  26. then the results are wrong but this does not happen for Free Pascal nor
  27. for GPC. */
  28. extern int pascal_is_string_type (struct type *type,int *length_pos,
  29. int *length_size, int *string_pos,
  30. struct type **char_type,
  31. const char **arrayname);
  32. /* Defined in p-lang.c */
  33. extern const char *pascal_main_name (void);
  34. /* These are in p-lang.c: */
  35. extern int is_pascal_string_type (struct type *, int *, int *, int *,
  36. struct type **, const char **);
  37. extern int pascal_object_is_vtbl_ptr_type (struct type *);
  38. extern int pascal_object_is_vtbl_member (struct type *);
  39. /* Class representing the Pascal language. */
  40. class pascal_language : public language_defn
  41. {
  42. public:
  43. pascal_language ()
  44. : language_defn (language_pascal)
  45. { /* Nothing. */ }
  46. /* See language.h. */
  47. const char *name () const override
  48. { return "pascal"; }
  49. /* See language.h. */
  50. const char *natural_name () const override
  51. { return "Pascal"; }
  52. /* See language.h. */
  53. const std::vector<const char *> &filename_extensions () const override
  54. {
  55. static const std::vector<const char *> extensions
  56. = { ".pas", ".p", ".pp" };
  57. return extensions;
  58. }
  59. /* See language.h. */
  60. void language_arch_info (struct gdbarch *gdbarch,
  61. struct language_arch_info *lai) const override;
  62. /* See language.h. */
  63. void print_type (struct type *type, const char *varstring,
  64. struct ui_file *stream, int show, int level,
  65. const struct type_print_options *flags) const override;
  66. /* See language.h. */
  67. void value_print (struct value *val, struct ui_file *stream,
  68. const struct value_print_options *options) const override;
  69. /* See language.h. */
  70. void value_print_inner
  71. (struct value *val, struct ui_file *stream, int recurse,
  72. const struct value_print_options *options) const override;
  73. /* See language.h. */
  74. int parser (struct parser_state *ps) const override;
  75. /* See language.h. */
  76. void emitchar (int ch, struct type *chtype,
  77. struct ui_file *stream, int quoter) const override
  78. {
  79. int in_quotes = 0;
  80. print_one_char (ch, stream, &in_quotes);
  81. if (in_quotes)
  82. gdb_puts ("'", stream);
  83. }
  84. /* See language.h. */
  85. void printchar (int ch, struct type *chtype,
  86. struct ui_file *stream) const override;
  87. /* See language.h. */
  88. void printstr (struct ui_file *stream, struct type *elttype,
  89. const gdb_byte *string, unsigned int length,
  90. const char *encoding, int force_ellipses,
  91. const struct value_print_options *options) const override;
  92. /* See language.h. */
  93. void print_typedef (struct type *type, struct symbol *new_symbol,
  94. struct ui_file *stream) const override;
  95. /* See language.h. */
  96. bool is_string_type_p (struct type *type) const override
  97. {
  98. return pascal_is_string_type(type, nullptr, nullptr, nullptr,
  99. nullptr, nullptr) > 0;
  100. }
  101. /* See language.h. */
  102. const char *name_of_this () const override
  103. { return "this"; }
  104. /* See language.h. */
  105. bool range_checking_on_by_default () const override
  106. { return true; }
  107. private:
  108. /* Print the character C on STREAM as part of the contents of a literal
  109. string. IN_QUOTES is reset to 0 if a char is written with #4 notation. */
  110. void print_one_char (int c, struct ui_file *stream, int *in_quotes) const;
  111. /* Print the name of the type (or the ultimate pointer target,
  112. function value or array element), or the description of a
  113. structure or union.
  114. SHOW positive means print details about the type (e.g. enum values),
  115. and print structure elements passing SHOW - 1 for show. SHOW negative
  116. means just print the type name or struct tag if there is one. If
  117. there is no name, print something sensible but concise like "struct
  118. {...}".
  119. SHOW zero means just print the type name or struct tag if there is one.
  120. If there is no name, print something sensible but not as concise like
  121. "struct {int x; int y;}".
  122. LEVEL is the number of spaces to indent by.
  123. We increase it for some recursive calls. */
  124. void type_print_base (struct type *type, struct ui_file *stream, int show,
  125. int level,
  126. const struct type_print_options *flags) const;
  127. /* Print any array sizes, function arguments or close parentheses
  128. needed after the variable name (to describe its type).
  129. Args work like pascal_type_print_varspec_prefix. */
  130. void type_print_varspec_suffix (struct type *type, struct ui_file *stream,
  131. int show, int passed_a_ptr,
  132. int demangled_args,
  133. const struct type_print_options *flags) const;
  134. /* Helper for pascal_language::type_print_varspec_suffix to print the
  135. suffix of a function or method. */
  136. void type_print_func_varspec_suffix
  137. (struct type *type, struct ui_file *stream, int show,
  138. int passed_a_ptr, int demangled_args,
  139. const struct type_print_options *flags) const;
  140. /* Print any asterisks or open-parentheses needed before the
  141. variable name (to describe its type).
  142. On outermost call, pass 0 for PASSED_A_PTR.
  143. On outermost call, SHOW > 0 means should ignore
  144. any typename for TYPE and show its details.
  145. SHOW is always zero on recursive calls. */
  146. void type_print_varspec_prefix
  147. (struct type *type, struct ui_file *stream, int show,
  148. int passed_a_ptr, const struct type_print_options *flags) const;
  149. /* Print the function args from TYPE (a TYPE_CODE_FUNC) to STREAM taking
  150. FLAGS into account where appropriate. */
  151. void print_func_args (struct type *type, struct ui_file *stream,
  152. const struct type_print_options *flags) const;
  153. /* Print the Pascal method arguments for PHYSNAME and METHODNAME to the
  154. file STREAM. */
  155. void type_print_method_args (const char *physname, const char *methodname,
  156. struct ui_file *stream) const;
  157. /* If TYPE is a derived type, then print out derivation information.
  158. Print only the actual base classes of this type, not the base classes
  159. of the base classes. I.e. for the derivation hierarchy:
  160. class A { int a; };
  161. class B : public A {int b; };
  162. class C : public B {int c; };
  163. Print the type of class C as:
  164. class C : public B {
  165. int c;
  166. }
  167. Not as the following (like gdb used to), which is not legal C++ syntax
  168. for derived types and may be confused with the multiple inheritance
  169. form:
  170. class C : public B : public A {
  171. int c;
  172. }
  173. In general, gdb should try to print the types as closely as possible
  174. to the form that they appear in the source code. */
  175. void type_print_derivation_info (struct ui_file *stream,
  176. struct type *type) const;
  177. };
  178. #endif /* P_LANG_H */