⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 language.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Multiple source language support for GDB.   Copyright 1991, 1992 Free Software Foundation, Inc.   Contributed by the Department of Computer Science at the State University   of New York at Buffalo.This file is part of GDB.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  *//* This file contains functions that return things that are specific   to languages.  Each function should examine current_language if necessary,   and return the appropriate result. *//* FIXME:  Most of these would be better organized as macros which   return data out of a "language-specific" struct pointer that is set   whenever the working language changes.  That would be a lot faster.  */#include "defs.h"#include <string.h>#include <varargs.h>#include "symtab.h"#include "gdbtypes.h"#include "value.h"#include "gdbcmd.h"#include "frame.h"#include "expression.h"#include "language.h"#include "target.h"#include "parser-defs.h"static voidshow_language_command PARAMS ((char *, int));static voidset_language_command PARAMS ((char *, int));static voidshow_type_command PARAMS ((char *, int));static voidset_type_command PARAMS ((char *, int));static voidshow_range_command PARAMS ((char *, int));static voidset_range_command PARAMS ((char *, int));static voidset_range_str PARAMS ((void));static voidset_type_str PARAMS ((void));static voidset_lang_str PARAMS ((void));static voidunk_lang_error PARAMS ((char *));static intunk_lang_parser PARAMS ((void));static voidshow_check PARAMS ((char *, int));static voidset_check PARAMS ((char *, int));static voidset_type_range PARAMS ((void));/* Forward declaration */extern const struct language_defn unknown_language_defn;extern char *warning_pre_print;  /* The current (default at startup) state of type and range checking.    (If the modes are set to "auto", though, these are changed based    on the default language at startup, and then again based on the    language of the first source file.  */enum range_mode range_mode = range_mode_auto;enum range_check range_check = range_check_off;enum type_mode type_mode = type_mode_auto;enum type_check type_check = type_check_off;/* The current language and language_mode (see language.h) */const struct language_defn *current_language = &unknown_language_defn;enum language_mode language_mode = language_mode_auto;/* The language that the user expects to be typing in (the language   of main(), or the last language we notified them about, or C).  */const struct language_defn *expected_language;/* The list of supported languages.  The list itself is malloc'd.  */static const struct language_defn **languages;static unsigned languages_size;static unsigned languages_allocsize;#define	DEFAULT_ALLOCSIZE 3/* The "set language/type/range" commands all put stuff in these   buffers.  This is to make them work as set/show commands.  The   user's string is copied here, then the set_* commands look at   them and update them to something that looks nice when it is   printed out. */static char *language;static char *type;static char *range;/* Warning issued when current_language and the language of the current   frame do not match. */char lang_frame_mismatch_warn[] =	"Warning: the current language does not match this frame.";/* This page contains the functions corresponding to GDB commands   and their helpers. *//* Show command.  Display a warning if the language set   does not match the frame. */static voidshow_language_command (ignore, from_tty)   char *ignore;   int from_tty;{   enum language flang;		/* The language of the current frame */   flang = get_frame_language();   if (flang != language_unknown &&      language_mode == language_mode_manual &&      current_language->la_language != flang)      printf_filtered("%s\n",lang_frame_mismatch_warn);}/* Set command.  Change the current working language. */static voidset_language_command (ignore, from_tty)   char *ignore;   int from_tty;{  int i;  enum language flang;  char *err_lang;  /* FIXME -- do this from the list, with HELP.  */  if (!language || !language[0]) {    printf("The currently understood settings are:\n\n\local or auto    Automatic setting based on source file\n\c                Use the C language\n\c++              Use the C++ language\n\modula-2         Use the Modula-2 language\n");    /* Restore the silly string. */    set_language(current_language->la_language);    return;  }  /* Search the list of languages for a match.  */  for (i = 0; i < languages_size; i++) {    if (!strcmp (languages[i]->la_name, language)) {      /* Found it!  Go into manual mode, and use this language.  */      if (languages[i]->la_language == language_auto) {	/* Enter auto mode.  Set to the current frame's language, if known.  */	language_mode = language_mode_auto;  	flang = get_frame_language();	if (flang!=language_unknown)	  set_language(flang);	expected_language = current_language;	return;      } else {	/* Enter manual mode.  Set the specified language.  */	language_mode = language_mode_manual;	current_language = languages[i];	set_type_range ();	set_lang_str();	expected_language = current_language;	return;      }    }  }  /* Reset the language (esp. the global string "language") to the      correct values. */  err_lang=savestring(language,strlen(language));  make_cleanup (free, err_lang);	/* Free it after error */  set_language(current_language->la_language);  error ("Unknown language `%s'.",err_lang);}/* Show command.  Display a warning if the type setting does   not match the current language. */static voidshow_type_command(ignore, from_tty)   char *ignore;   int from_tty;{   if (type_check != current_language->la_type_check)      printf("Warning: the current type check setting does not match the language.\n");}/* Set command.  Change the setting for type checking. */static voidset_type_command(ignore, from_tty)   char *ignore;   int from_tty;{   if (!strcmp(type,"on"))   {      type_check = type_check_on;      type_mode = type_mode_manual;   }   else if (!strcmp(type,"warn"))   {      type_check = type_check_warn;      type_mode = type_mode_manual;   }   else if (!strcmp(type,"off"))   {      type_check = type_check_off;      type_mode = type_mode_manual;   }   else if (!strcmp(type,"auto"))   {      type_mode = type_mode_auto;      set_type_range();      /* Avoid hitting the set_type_str call below.  We         did it in set_type_range. */      return;   }   set_type_str();   show_type_command((char *)NULL, from_tty);}/* Show command.  Display a warning if the range setting does   not match the current language. */static voidshow_range_command(ignore, from_tty)   char *ignore;   int from_tty;{   if (range_check != current_language->la_range_check)      printf("Warning: the current range check setting does not match the language.\n");}/* Set command.  Change the setting for range checking. */static voidset_range_command(ignore, from_tty)   char *ignore;   int from_tty;{   if (!strcmp(range,"on"))   {      range_check = range_check_on;      range_mode = range_mode_manual;   }   else if (!strcmp(range,"warn"))   {      range_check = range_check_warn;      range_mode = range_mode_manual;   }   else if (!strcmp(range,"off"))   {      range_check = range_check_off;      range_mode = range_mode_manual;   }   else if (!strcmp(range,"auto"))   {      range_mode = range_mode_auto;      set_type_range();      /* Avoid hitting the set_range_str call below.  We	 did it in set_type_range. */      return;   }   set_range_str();   show_range_command((char *)0, from_tty);}/* Set the status of range and type checking based on   the current modes and the current language.   If SHOW is non-zero, then print out the current language,   type and range checking status. */static voidset_type_range(){  if (range_mode == range_mode_auto)    range_check = current_language->la_range_check;  if (type_mode == type_mode_auto)    type_check = current_language->la_type_check;  set_type_str();  set_range_str();}/* Set current language to (enum language) LANG.  */voidset_language(lang)   enum language lang;{  int i;  for (i = 0; i < languages_size; i++) {    if (languages[i]->la_language == lang) {      current_language = languages[i];      set_type_range ();      set_lang_str();      break;    }  }}/* This page contains functions that update the global vars   language, type and range. */static voidset_lang_str(){   char *prefix = "";   free (language);   if (language_mode == language_mode_auto)      prefix = "auto; currently ";   language = concat(prefix, current_language->la_name, NULL);}static voidset_type_str(){   char *tmp, *prefix = "";   free (type);   if (type_mode==type_mode_auto)      prefix = "auto; currently ";   switch(type_check)   {   case type_check_on:      tmp = "on";      break;   case type_check_off:      tmp = "off";      break;   case type_check_warn:      tmp = "warn";      break;      default:      error ("Unrecognized type check setting.");   }   type = concat(prefix,tmp,NULL);}static voidset_range_str(){   char *tmp, *pref = "";   free (range);   if (range_mode==range_mode_auto)      pref = "auto; currently ";   switch(range_check)   {   case range_check_on:      tmp = "on";      break;   case range_check_off:      tmp = "off";      break;   case range_check_warn:      tmp = "warn";      break;      default:      error ("Unrecognized range check setting.");   }   range = concat(pref,tmp,NULL);}/* Print out the current language settings: language, range and   type checking.  If QUIETLY, print only what has changed.  */voidlanguage_info (quietly)     int quietly;{  if (quietly && expected_language == current_language)    return;  expected_language = current_language;  printf("Current language:  %s\n",language);  show_language_command((char *)0, 1);  if (!quietly)    {       printf("Type checking:     %s\n",type);       show_type_command((char *)0, 1);       printf("Range checking:    %s\n",range);       show_range_command((char *)0, 1);    }}/* Return the result of a binary operation. */#if 0	/* Currently unused */struct type *binop_result_type(v1,v2)   value v1,v2;{   int l1,l2,size,uns;   l1 = TYPE_LENGTH(VALUE_TYPE(v1));   l2 = TYPE_LENGTH(VALUE_TYPE(v2));   switch(current_language->la_language)   {   case language_c:   case language_cplus:      if (TYPE_CODE(VALUE_TYPE(v1))==TYPE_CODE_FLT)	 return TYPE_CODE(VALUE_TYPE(v2)) == TYPE_CODE_FLT && l2 > l1 ?	    VALUE_TYPE(v2) : VALUE_TYPE(v1);      else if (TYPE_CODE(VALUE_TYPE(v2))==TYPE_CODE_FLT)	 return TYPE_CODE(VALUE_TYPE(v1)) == TYPE_CODE_FLT && l1 > l2 ?	    VALUE_TYPE(v1) : VALUE_TYPE(v2);      else if (TYPE_UNSIGNED(VALUE_TYPE(v1)) && l1 > l2)	 return VALUE_TYPE(v1);      else if (TYPE_UNSIGNED(VALUE_TYPE(v2)) && l2 > l1)	 return VALUE_TYPE(v2);      else  /* Both are signed.  Result is the longer type */	 return l1 > l2 ? VALUE_TYPE(v1) : VALUE_TYPE(v2);      break;   case language_m2:      /* If we are doing type-checking, l1 should equal l2, so this is	 not needed. */      return l1 > l2 ? VALUE_TYPE(v1) : VALUE_TYPE(v2);      break;   }   abort();   return (struct type *)0;	/* For lint */}#endif	/* 0 *//* This page contains functions that return format strings for   printf for printing out numbers in different formats *//* Returns the appropriate printf format for hexadecimal   numbers. */char *local_hex_format_custom(pre)   char *pre;{   static char form[50];   strcpy (form, current_language->la_hex_format_pre);   strcat (form, pre);   strcat (form, current_language->la_hex_format_suf);   return form;}/* Converts a number to hexadecimal and stores it in a static   string.  Returns a pointer to this string. */char *local_hex_string (num)   int num;{   static char res[50];   sprintf (res, current_language->la_hex_format, num);   return res;}/* Converts a number to custom hexadecimal and stores it in a static   string.  Returns a pointer to this string. */char *local_hex_string_custom(num,pre)   int num;   char *pre;{   static char res[50];   sprintf (res, local_hex_format_custom(pre), num);   return res;}/* Returns the appropriate printf format for octal   numbers. */char *local_octal_format_custom(pre)   char *pre;{   static char form[50];   strcpy (form, current_language->la_octal_format_pre);   strcat (form, pre);   strcat (form, current_language->la_octal_format_suf);   return form;}/* This page contains functions that are used in type/range checking.   They all return zero if the type/range check fails.   It is hoped that these will make extending GDB to parse different   languages a little easier.  These are primarily used in eval.c when   evaluating expressions and making sure that their types are correct.   Instead of having a mess of conjucted/disjuncted expressions in an "if",   the ideas of type can be wrapped up in the following functions.   Note that some of them are not currently dependent upon which language   is currently being parsed.  For example, floats are the same in   C and Modula-2 (ie. the only floating point type has TYPE_CODE of   TYPE_CODE_FLT), while booleans are different. *//* Returns non-zero if its argument is a simple type.  This is the same for   both Modula-2 and for C.  In the C case, TYPE_CODE_CHAR will never occur,   and thus will never cause the failure of the test. */intsimple_type(type)    struct type *type;{  switch (TYPE_CODE (type)) {  case TYPE_CODE_INT:  case TYPE_CODE_CHAR:  case TYPE_CODE_ENUM:  case TYPE_CODE_FLT:  case TYPE_CODE_RANGE:  case TYPE_CODE_BOOL:    return 1;  default:    return 0;  }}/* Returns non-zero if its argument is of an ordered type. */intordered_type (type)   struct type *type;{  switch (TYPE_CODE (type)) {  case TYPE_CODE_INT:  case TYPE_CODE_CHAR:  case TYPE_CODE_ENUM:  case TYPE_CODE_FLT:  case TYPE_CODE_RANGE:    return 1;  default:    return 0;  }}/* Returns non-zero if the two types are the same */intsame_type (arg1, arg2)   struct type *arg1, *arg2;{   if (structured_type(arg1) ? !structured_type(arg2) : structured_type(arg2))      /* One is structured and one isn't */      return 0;   else if (structured_type(arg1) && structured_type(arg2))      return arg1 == arg2;   else if (numeric_type(arg1) && numeric_type(arg2))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -