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

📄 tree_no_comment.c

📁 使用yacc和lex编写的cmm语言的词法分析和语法分析程序.
💻 C
📖 第 1 页 / 共 4 页
字号:
extern int xmalloc ();extern void free ();struct obstack permanent_obstack;struct obstack *function_maybepermanent_obstack;struct obstack maybepermanent_obstack;struct obstack *function_obstack;struct obstack temporary_obstack;struct obstack momentary_obstack;static struct obstack temp_decl_obstack;struct obstack *saveable_obstack;struct obstack *rtl_obstack;struct obstack *current_obstack;struct obstack *expression_obstack;struct obstack_stack{  struct obstack_stack *next;  struct obstack *current;  struct obstack *saveable;  struct obstack *expression;  struct obstack *rtl;};struct obstack_stack *obstack_stack;static struct obstack obstack_stack_obstack;char *maybepermanent_firstobj;char *temporary_firstobj;char *momentary_firstobj;char *temp_decl_firstobj;int all_types_permanent;struct momentary_level{    struct momentary_level *prev;    char *base;    struct obstack *obstack;};struct momentary_level *momentary_stack;char *standard_tree_code_type[] = {};int standard_tree_code_length[] = {};char *standard_tree_code_name[] = {};char **tree_code_type;int *tree_code_length;char **tree_code_name;typedef enum{  d_kind, t_kind, s_kind, r_kind, e_kind, c_kind,  id_kind, op_id_kind, perm_list_kind, temp_list_kind,  vec_kind, x_kind, lang_decl, lang_type, all_kinds} tree_node_kind;int tree_node_counts[(int)all_kinds];int tree_node_sizes[(int)all_kinds];int id_string_size = 0;char *tree_node_kind_names[] = { "decls", "types", "stmts", "refs", "exprs", "constants",				 "identifiers", "op_identifiers", "perm_tree_lists", "temp_tree_lists",				 "vecs", "random kinds", "lang_decl kinds", "lang_type kinds" };static tree hash_table[MAX_HASH_TABLE];	static int do_identifier_warnings;extern char *mode_name[];void gcc_obstack_init ();static tree stabilize_reference_1 ();voidinit_obstacks (){  gcc_obstack_init (&obstack_stack_obstack);  gcc_obstack_init (&permanent_obstack);  gcc_obstack_init (&temporary_obstack);  temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);  gcc_obstack_init (&momentary_obstack);  momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);  gcc_obstack_init (&maybepermanent_obstack);  maybepermanent_firstobj    = (char *) obstack_alloc (&maybepermanent_obstack, 0);  gcc_obstack_init (&temp_decl_obstack);  temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);  function_obstack = &temporary_obstack;  function_maybepermanent_obstack = &maybepermanent_obstack;  current_obstack = &permanent_obstack;  expression_obstack = &permanent_obstack;  rtl_obstack = saveable_obstack = &permanent_obstack;    bzero (hash_table, sizeof hash_table);}voidgcc_obstack_init (obstack)     struct obstack *obstack;{      _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,		  (void *(*) ()) OBSTACK_CHUNK_ALLOC,		  (void (*) ()) OBSTACK_CHUNK_FREE);}voidsave_tree_status (p)     struct function *p;{  p->all_types_permanent = all_types_permanent;  p->momentary_stack = momentary_stack;  p->maybepermanent_firstobj = maybepermanent_firstobj;  p->momentary_firstobj = momentary_firstobj;  p->function_obstack = function_obstack;  p->function_maybepermanent_obstack = function_maybepermanent_obstack;  p->current_obstack = current_obstack;  p->expression_obstack = expression_obstack;  p->saveable_obstack = saveable_obstack;  p->rtl_obstack = rtl_obstack;  function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));  gcc_obstack_init (function_obstack);  function_maybepermanent_obstack    = (struct obstack *) xmalloc (sizeof (struct obstack));  gcc_obstack_init (function_maybepermanent_obstack);  current_obstack = &permanent_obstack;  expression_obstack = &permanent_obstack;  rtl_obstack = saveable_obstack = &permanent_obstack;  momentary_firstobj = (char *) obstack_finish (&momentary_obstack);  maybepermanent_firstobj    = (char *) obstack_finish (function_maybepermanent_obstack);}voidrestore_tree_status (p)     struct function *p;{  all_types_permanent = p->all_types_permanent;  momentary_stack = p->momentary_stack;  obstack_free (&momentary_obstack, momentary_firstobj);  obstack_free (function_obstack, 0);  obstack_free (function_maybepermanent_obstack, 0);  free (function_obstack);  momentary_firstobj = p->momentary_firstobj;  maybepermanent_firstobj = p->maybepermanent_firstobj;  function_obstack = p->function_obstack;  function_maybepermanent_obstack = p->function_maybepermanent_obstack;  current_obstack = p->current_obstack;  expression_obstack = p->expression_obstack;  saveable_obstack = p->saveable_obstack;  rtl_obstack = p->rtl_obstack;}voidtemporary_allocation (){    current_obstack = function_obstack;  expression_obstack = function_obstack;  rtl_obstack = saveable_obstack = function_maybepermanent_obstack;  momentary_stack = 0;}voidend_temporary_allocation (){  current_obstack = &permanent_obstack;  expression_obstack = &permanent_obstack;  rtl_obstack = saveable_obstack = &permanent_obstack;}voidresume_temporary_allocation (){  current_obstack = function_obstack;  expression_obstack = function_obstack;  rtl_obstack = saveable_obstack = function_maybepermanent_obstack;}voidsaveable_allocation (){    expression_obstack = current_obstack = saveable_obstack;}voidpush_obstacks (current, saveable)     struct obstack *current, *saveable;{  struct obstack_stack *p    = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,					      (sizeof (struct obstack_stack)));  p->current = current_obstack;  p->saveable = saveable_obstack;  p->expression = expression_obstack;  p->rtl = rtl_obstack;  p->next = obstack_stack;  obstack_stack = p;  current_obstack = current;  expression_obstack = current;  rtl_obstack = saveable_obstack = saveable;}voidpush_obstacks_nochange (){  struct obstack_stack *p    = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,					      (sizeof (struct obstack_stack)));  p->current = current_obstack;  p->saveable = saveable_obstack;  p->expression = expression_obstack;  p->rtl = rtl_obstack;  p->next = obstack_stack;  obstack_stack = p;}voidpop_obstacks (){  struct obstack_stack *p = obstack_stack;  obstack_stack = p->next;  current_obstack = p->current;  saveable_obstack = p->saveable;  expression_obstack = p->expression;  rtl_obstack = p->rtl;  obstack_free (&obstack_stack_obstack, p);}intallocation_temporary_p (){  return current_obstack != &permanent_obstack;}voidpermanent_allocation (){    obstack_free (&temporary_obstack, temporary_firstobj);  obstack_free (&momentary_obstack, momentary_firstobj);  obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);  obstack_free (&temp_decl_obstack, temp_decl_firstobj);  current_obstack = &permanent_obstack;  expression_obstack = &permanent_obstack;  rtl_obstack = saveable_obstack = &permanent_obstack;}voidpreserve_data (){  maybepermanent_firstobj    = (char *) obstack_alloc (function_maybepermanent_obstack, 0);}voidpreserve_initializer (){  temporary_firstobj    = (char *) obstack_alloc (&temporary_obstack, 0);  momentary_firstobj    = (char *) obstack_alloc (&momentary_obstack, 0);  maybepermanent_firstobj    = (char *) obstack_alloc (function_maybepermanent_obstack, 0);}voidrtl_in_current_obstack (){  rtl_obstack = current_obstack;}intrtl_in_saveable_obstack (){  if (rtl_obstack == current_obstack)    {      rtl_obstack = saveable_obstack;      return 1;    }  else    return 0;}char *oballoc (size)     int size;{  return (char *) obstack_alloc (current_obstack, size);}voidobfree (ptr)     char *ptr;{  obstack_free (current_obstack, ptr);}char *permalloc (size)     long size;{  return (char *) obstack_alloc (&permanent_obstack, size);}char *perm_calloc (nelem, size)     int nelem;     long size;{  char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);  bzero (rval, nelem * size);  return rval;}char *savealloc (size)     int size;{  return (char *) obstack_alloc (saveable_obstack, size);}voiddebug_obstack (object)     char *object;{  struct obstack *obstack = NULL;  char *obstack_name = NULL;  struct function *p;  for (p = outer_function_chain; p; p = p->next)    {      if (_obstack_allocated_p (p->function_obstack, object))	{	  obstack = p->function_obstack;	  obstack_name = "containing function obstack";	}      if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))	{	  obstack = p->function_maybepermanent_obstack;	  obstack_name = "containing function maybepermanent obstack";	}    }  if (_obstack_allocated_p (&obstack_stack_obstack, object))    {      obstack = &obstack_stack_obstack;      obstack_name = "obstack_stack_obstack";    }  else if (_obstack_allocated_p (function_obstack, object))    {      obstack = function_obstack;      obstack_name = "function obstack";    }  else if (_obstack_allocated_p (&permanent_obstack, object))    {      obstack = &permanent_obstack;      obstack_name = "permanent_obstack";    }  else if (_obstack_allocated_p (&momentary_obstack, object))    {      obstack = &momentary_obstack;      obstack_name = "momentary_obstack";    }  else if (_obstack_allocated_p (function_maybepermanent_obstack, object))    {      obstack = function_maybepermanent_obstack;      obstack_name = "function maybepermanent obstack";    }  else if (_obstack_allocated_p (&temp_decl_obstack, object))    {      obstack = &temp_decl_obstack;      obstack_name = "temp_decl_obstack";    }    if (obstack != NULL)    {      if (object >= obstack->next_free	  && object < obstack->chunk_limit)	fprintf (stderr, "object in free portion of obstack %s.\n",		 obstack_name);      else	fprintf (stderr, "object allocated from %s.\n", obstack_name);    }  else    fprintf (stderr, "object not allocated from any obstack.\n");}intobject_permanent_p (obj)     tree obj;{  return _obstack_allocated_p (&permanent_obstack, obj);}voidpush_momentary (){  struct momentary_level *tem    = (struct momentary_level *) obstack_alloc (&momentary_obstack,						sizeof (struct momentary_level));  tem->prev = momentary_stack;  tem->base = (char *) obstack_base (&momentary_obstack);  tem->obstack = expression_obstack;  momentary_stack = tem;  expression_obstack = &momentary_obstack;}voidclear_momentary (){  obstack_free (&momentary_obstack, momentary_stack->base);}voidpop_momentary (){  struct momentary_level *tem = momentary_stack;  momentary_stack = tem->prev;  expression_obstack = tem->obstack;  obstack_free (&momentary_obstack, tem);}intsuspend_momentary (){  register int tem = expression_obstack == &momentary_obstack;  expression_obstack = saveable_obstack;  return tem;}voidresume_momentary (yes)     int yes;{  if (yes)    expression_obstack = &momentary_obstack;}voidinit_tree_codes (){  tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));  tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));  tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));  bcopy (standard_tree_code_type, tree_code_type,	 sizeof (standard_tree_code_type));  bcopy (standard_tree_code_length, tree_code_length,	 sizeof (standard_tree_code_length));  bcopy (standard_tree_code_name, tree_code_name,	 sizeof (standard_tree_code_name));}treemake_node (code)     enum tree_code code;{  register tree t;  register int type = TREE_CODE_CLASS (code);  register int length;  register struct obstack *obstack = current_obstack;  register int i;  register tree_node_kind kind;  switch (type)    {    case 'd':        kind = d_kind;      length = sizeof (struct tree_decl);            if (obstack != &permanent_obstack)	obstack = saveable_obstack;            else if (code == PARM_DECL)	obstack = function_maybepermanent_obstack;      break;    case 't':        kind = t_kind;      length = sizeof (struct tree_type);            if (obstack != &permanent_obstack)	obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;      break;    case 's':        kind = s_kind;      goto usual_kind;    case 'r':        kind = r_kind;      goto usual_kind;    case 'e':      case '<':      case '1':      case '2':        kind = e_kind;    usual_kind:      obstack = expression_obstack;            if ((code == BLOCK || code == BIND_EXPR)	  && obstack != &permanent_obstack)	obstack = saveable_obstack;      length = sizeof (struct tree_exp)	+ (tree_code_length[(int) code] - 1) * sizeof (char *);      break;    case 'c':        kind = c_kind;      obstack = expression_obstack;            if (code == REAL_CST)	{	  length = sizeof (struct tree_real_cst);	  break;	}    case 'x':        if (code == IDENTIFIER_NODE)	kind = id_kind;      else if (code == OP_IDENTIFIER)	kind = op_id_kind;      else if (code == TREE_VEC)	kind = vec_kind;      else	kind = x_kind;      length = sizeof (struct tree_common)	+ tree_code_length[(int) code] * sizeof (char *);            if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;    }  t = (tree) obstack_alloc (obstack, length);  tree_node_counts[(int)kind]++;  tree_node_sizes[(int)kind] += length;  TREE_TYPE (t) = 0;  TREE_CHAIN (t) = 0;  for (i = (length / sizeof (int)) - 1;       i >= sizeof (struct tree_common) / sizeof (int) - 1;       i--)    ((int *) t)[i] = 0;  TREE_SET_CODE (t, code);  if (obstack == &permanent_obstack)    TREE_PERMANENT (t) = 1;  switch (type)    {    case 's':      TREE_SIDE_EFFECTS (t) = 1;      TREE_TYPE (t) = void_type_node;      break;    case 'd':      DECL_ALIGN (t) = 1;      DECL_SOURCE_LINE (t) = lineno;      DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";      break;    case 't':      {	static unsigned next_type_uid = 1;	TYPE_UID (t) = next_type_uid++;      }      TYPE_ALIGN (t) = 1;      TYPE_MAIN_VARIANT (t) = t;      break;    case 'c':      TREE_CONSTANT (t) = 1;      break;    }  return t;}treecopy_node (node)     tree node;

⌨️ 快捷键说明

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