📄 lex.c
字号:
{ /* #ident. The pedantic warning is now in cccp.c. */ /* Here we have just seen `#ident '. A string constant should follow. */ while (c == ' ' || c == '\t') c = getlc (finput); /* If no argument, ignore the line. */ if (c == '\n') return c; ungetc (c, finput); token = yylex (); if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) { error ("invalid #ident"); goto skipline; } if (!flag_no_ident) {#ifdef ASM_OUTPUT_IDENT extern FILE *asm_out_file; ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));#endif } /* Skip the rest of this line. */ goto skipline; } }#endif error ("undefined or invalid # directive"); goto skipline; }linenum: /* Here we have either `#line' or `# <nonletter>'. In either case, it should be a line number; a digit should follow. */ while (c == ' ' || c == '\t') c = getlc (finput); /* If the # is the only nonwhite char on the line, just ignore it. Check the new newline. */ if (c == '\n') return c; /* Something follows the #; read a token. */ if (ISDIGIT(c)) { int old_lineno = lineno; int used_up = 0; int l = 0; extern struct obstack permanent_obstack; do { l = l * 10 + (c - '0'); /* FIXME Not portable */ c = getlc(finput); } while (ISDIGIT(c)); /* subtract one, because it is the following line that gets the specified number */ l--; /* Is this the last nonwhite stuff on the line? */ c = getlc (finput); while (c == ' ' || c == '\t') c = getlc (finput); if (c == '\n') { /* No more: store the line number and check following line. */ lineno = l; return c; } /* More follows: it must be a string constant (filename). */ /* Read the string constant, but don't treat \ as special. */ ignore_escape_flag = 1; ignore_escape_flag = 0; if (c != '\"') { error ("invalid #line"); goto skipline; } for (;;) { c = getc (finput); if (c == EOF || c == '\n') { error ("invalid #line"); return c; } if (c == '\"') { obstack_1grow(&permanent_obstack, 0); input_filename = obstack_finish (&permanent_obstack); break; } obstack_1grow(&permanent_obstack, c); } lineno = l; /* Each change of file name reinitializes whether we are now in a system header. */ in_system_header = 0; if (main_input_filename == 0) main_input_filename = input_filename; /* Is this the last nonwhite stuff on the line? */ c = getlc (finput); while (c == ' ' || c == '\t') c = getlc (finput); if (c == '\n') return c; used_up = 0; /* `1' after file name means entering new file. `2' after file name means just left a file. */ if (ISDIGIT (c)) { if (c == '1') { /* Pushing to a new file. */ struct file_stack *p = (struct file_stack *) xmalloc (sizeof (struct file_stack)); input_file_stack->line = old_lineno; p->next = input_file_stack; p->name = input_filename; input_file_stack = p; input_file_stack_tick++;#ifdef DWARF_DEBUGGING_INFO if (debug_info_level == DINFO_LEVEL_VERBOSE && write_symbols == DWARF_DEBUG) dwarfout_start_new_source_file (input_filename);#endif /* DWARF_DEBUGGING_INFO */ used_up = 1; } else if (c == '2') { /* Popping out of a file. */ if (input_file_stack->next) { struct file_stack *p = input_file_stack; input_file_stack = p->next; free (p); input_file_stack_tick++;#ifdef DWARF_DEBUGGING_INFO if (debug_info_level == DINFO_LEVEL_VERBOSE && write_symbols == DWARF_DEBUG) dwarfout_resume_previous_source_file (input_file_stack->line);#endif /* DWARF_DEBUGGING_INFO */ } else error ("#-lines for entering and leaving files don't match"); used_up = 1; } } /* If we have handled a `1' or a `2', see if there is another number to read. */ if (used_up) { /* Is this the last nonwhite stuff on the line? */ c = getlc (finput); while (c == ' ' || c == '\t') c = getlc (finput); if (c == '\n') return c; used_up = 0; } /* `3' after file name means this is a system header file. */ if (c == '3') in_system_header = 1; } else error ("invalid #-line"); /* skip the rest of this line. */ skipline: while (c != '\n' && c != EOF) c = getc (finput); return c;}treeget_chill_filename (){ return (build_chill_string ( strlen (input_filename) + 1, /* +1 to get a zero terminated string */ input_filename));}treeget_chill_linenumber (){ return build_int_2 ((HOST_WIDE_INT)lineno, 0);}/* Assuming '/' and '*' have been read, skip until we've read the terminating '*' and '/'. */static voidskip_c_comment (){ int c = input(); int start_line = lineno; inside_c_comment++; for (;;) if (c == EOF) { error_with_file_and_line (input_filename, start_line, "unterminated comment"); break; } else if (c != '*') c = input(); else if ((c = input ()) == '/') break; inside_c_comment--;}/* Assuming "--" has been read, skip until '\n'. */static voidskip_line_comment (){ for (;;) { int c = input (); if (c == EOF) return; if (c == '\n') break; } unput ('\n');}static intskip_whitespace (){ for (;;) { int c = input (); if (c == EOF) return c; if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v') continue; if (c == '/') { c = input (); if (c == '*') { skip_c_comment (); continue; } else { unput (c); return '/'; } } if (c == '-') { c = input (); if (c == '-') { skip_line_comment (); continue; } else { unput (c); return '-'; } } return c; }}/* * avoid recursive calls to yylex to parse the ' = digits' or * ' = SYNvalue' which are supposed to follow certain compiler * directives. Read the input stream, and return the value parsed. */ /* FIXME: overflow check in here */ /* FIXME: check for EOF around here */static treeequal_number (){ int c, result; char *tokenbuf; char *cursor; tree retval = integer_zero_node; c = skip_whitespace(); if ((char)c != '=') { if (pass == 2) error ("missing `=' in compiler directive"); return integer_zero_node; } c = skip_whitespace(); /* collect token into tokenbuf for later analysis */ while (TRUE) { if (ISSPACE (c) || c == '<') break; obstack_1grow (&temporary_obstack, c); c = input (); } unput (c); /* put uninteresting char back */ obstack_1grow (&temporary_obstack, '\0'); /* terminate token */ tokenbuf = obstack_finish (&temporary_obstack); maybe_downcase (tokenbuf); if (*tokenbuf == '-') /* will fail in the next test */ result = BITSTRING; else if (maybe_number (tokenbuf)) { if (pass == 1) return integer_zero_node; push_obstacks_nochange (); end_temporary_allocation (); yylval.ttype = convert_integer (tokenbuf); tokenbuf = 0; /* Was freed by convert_integer. */ result = yylval.ttype ? NUMBER : 0; pop_obstacks (); } else result = 0; if (result == NUMBER) { retval = yylval.ttype; } else if (result == BITSTRING) { if (pass == 1) error ("invalid value follows `=' in compiler directive"); goto finish; } else /* not a number */ { cursor = tokenbuf; c = *cursor; if (!ISALPHA (c) && c != '_') { if (pass == 1) error ("invalid value follows `=' in compiler directive"); goto finish; } for (cursor = &tokenbuf[1]; *cursor != '\0'; cursor++) if (ISALPHA ((unsigned char) *cursor) || *cursor == '_' || ISDIGIT (*cursor)) continue; else { if (pass == 1) error ("invalid `%c' character in name", *cursor); goto finish; } if (pass == 1) goto finish; else { tree value = lookup_name (get_identifier (tokenbuf)); if (value == NULL_TREE || TREE_CODE (value) != CONST_DECL || TREE_CODE (DECL_INITIAL (value)) != INTEGER_CST) { if (pass == 2) error ("`%s' not integer constant synonym ", tokenbuf); goto finish; } obstack_free (&temporary_obstack, tokenbuf); tokenbuf = 0; push_obstacks_nochange (); end_temporary_allocation (); retval = convert (chill_taskingcode_type_node, DECL_INITIAL (value)); pop_obstacks (); } } /* check the value */ if (TREE_CODE (retval) != INTEGER_CST) { if (pass == 2) error ("invalid value follows `=' in compiler directive"); } else if (TREE_INT_CST_HIGH (retval) != 0 || TREE_INT_CST_LOW (retval) > TREE_INT_CST_LOW (TYPE_MAX_VALUE (chill_unsigned_type_node))) { if (pass == 2) error ("value out of range in compiler directive"); } finish: if (tokenbuf) obstack_free (&temporary_obstack, tokenbuf); return retval;}/* * add a possible grant-file path to the list */voidregister_seize_path (path) char *path;{ int pathlen = strlen (path); char *new_path = (char *)xmalloc (pathlen + 1); STRING_LIST *pl = (STRING_LIST *)xmalloc (sizeof (STRING_LIST)); /* strip off trailing slash if any */ if (path[pathlen - 1] == '/') pathlen--; memcpy (new_path, path, pathlen); pl->str = new_path; pl->next = seize_path_list; seize_path_list = pl;}/* Used by decode_decl to indicate that a <> use_seize_file NAME <> directive has been written to the grantfile. */voidmark_use_seizefile_written (name) tree name;{ tree node; for (node = files_to_seize; node != NULL_TREE; node = TREE_CHAIN (node)) if (TREE_VALUE (node) == name) { TREE_PURPOSE (node) = integer_one_node; break; }}static intyywrap (){ extern char *chill_real_input_filename; close_input_file (input_filename); use_seizefile_name = NULL_TREE; if (next_file_to_seize && !grant_only_flag) { FILE *grt_in = NULL; char *seizefile_name_chars = IDENTIFIER_POINTER (TREE_VALUE (next_file_to_seize)); /* find a seize file, open it. If it's not at the path the * user gave us, and that path contains no slashes, look on * the seize_file paths, specified by the '-I' options. */ grt_in = fopen (seizefile_name_chars, "r"); if (grt_in == NULL && strchr (seizefile_name_chars, '/') == NULL) { STRING_LIST *plp; char *path; for (plp = seize_path_list; plp != NULL; plp = plp->next) { path = (char *)xmalloc (strlen (seizefile_name_chars) + strlen (plp->str) + 2); sprintf (path, "%s/%s", plp->str, seizefile_name_chars); grt_in = fopen (path, "r"); if (grt_in == NULL) free (path); else { seizefile_name_chars = path; break; } } } if (grt_in == NULL) pfatal_with_name (seizefile_name_chars); finput = grt_in; input_filename = seizefile_name_chars; lineno = 0; current_seizefile_name = TREE_VALUE (next_file_to_seize); next_file_to_seize = TREE_CHAIN (next_file_to_seize); saw_eof = 0; return 0; } if (pass == 1) { next_file_to_seize = files_to_seize; current_seizefile_name = NULL_TREE; if (strcmp (main_input_filename, "stdin")) finput = fopen (chill_real_input_filename, "r"); else finput = stdin; if (finput == NULL) { error ("can't reopen %s", chill_real_input_filename); return 1; } input_filename = main_input_filename; ch_lex_init (); lineno = 0; /* Read a line directive if there is one. */ ungetc (check_newline (), finput); starting_pass_2 = 1; saw_eof = 0; if (module_number == 0) warning ("no modules seen"); return 0; } return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -