CBMC
preprocessor_line.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: ANSI-C Language Conversion
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "preprocessor_line.h"
13 
14 #include <cctype>
15 
16 #include <util/string2int.h>
17 #include <util/parser.h>
18 
20 
22  const char *text,
23  parsert &parser)
24 {
25  const char *ptr=text;
26  std::string line_number;
27 
28  // skip WS
29  while(*ptr==' ' || *ptr=='\t') ptr++;
30 
31  // skip #
32  if(*ptr!='#')
33  return;
34  ptr++;
35 
36  // skip WS
37  while(*ptr==' ' || *ptr=='\t') ptr++;
38 
39  // skip "line"
40  if(*ptr=='l')
41  {
42  while(*ptr!=0 && *ptr!=' ' && *ptr!='\t') ptr++;
43  }
44 
45  // skip WS
46  while(*ptr==' ' || *ptr=='\t') ptr++;
47 
48  // get line number
49  while(isdigit(*ptr))
50  {
51  line_number+=*ptr;
52  ptr++;
53  }
54 
55  // skip until "
56  while(*ptr!='\n' && *ptr!='"') ptr++;
57 
58  parser.set_line_no(unsafe_string2unsigned(line_number));
59 
60  // skip "
61  if(*ptr!='"')
62  return;
63 
64  ptr++;
65 
66  std::string file_name_tmp;
67 
68  // get file name
69  while(*ptr!='\n' && *ptr!='"')
70  {
71  file_name_tmp+=*ptr;
72  ptr++;
73  }
74 
75  std::string file_name_tmp2=unescape_string(file_name_tmp);
76  parser.set_file(file_name_tmp2);
77 }
Definition: parser.h:24
void set_file(const irep_idt &file)
Definition: parser.h:83
void set_line_no(unsigned _line_no)
Definition: parser.h:78
int isdigit(int c)
Definition: ctype.c:24
Parser utilities.
void preprocessor_line(const char *text, parsert &parser)
ANSI-C Language Conversion.
unsigned unsafe_string2unsigned(const std::string &str, int base)
Definition: string2int.cpp:35
std::string unescape_string(const std::string &src)
ANSI-C Language Conversion.