-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathpreprocessor_line.cpp
77 lines (55 loc) · 1.29 KB
/
preprocessor_line.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************\
Module: ANSI-C Language Conversion
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// ANSI-C Language Conversion
#include "preprocessor_line.h"
#include <cctype>
#include <util/string2int.h>
#include <util/parser.h>
#include "literals/unescape_string.h"
void preprocessor_line(
const char *text,
parsert &parser)
{
const char *ptr=text;
std::string line_number;
// skip WS
while(*ptr==' ' || *ptr=='\t') ptr++;
// skip #
if(*ptr!='#')
return;
ptr++;
// skip WS
while(*ptr==' ' || *ptr=='\t') ptr++;
// skip "line"
if(*ptr=='l')
{
while(*ptr!=0 && *ptr!=' ' && *ptr!='\t') ptr++;
}
// skip WS
while(*ptr==' ' || *ptr=='\t') ptr++;
// get line number
while(isdigit(*ptr))
{
line_number+=*ptr;
ptr++;
}
// skip until "
while(*ptr!='\n' && *ptr!='"') ptr++;
parser.set_line_no(unsafe_string2unsigned(line_number));
// skip "
if(*ptr!='"')
return;
ptr++;
std::string file_name_tmp;
// get file name
while(*ptr!='\n' && *ptr!='"')
{
file_name_tmp+=*ptr;
ptr++;
}
std::string file_name_tmp2=unescape_string(file_name_tmp);
parser.set_file(file_name_tmp2);
}