Commit c6d04218 authored by Alastair Robertson's avatar Alastair Robertson

Differentiate between system headers and relative paths

parent c2c9ade8
......@@ -178,8 +178,10 @@ using ProbeList = std::vector<Probe *>;
class Include : public Node {
public:
explicit Include(const std::string &file) : file(file) { }
explicit Include(const std::string &file, bool system_header)
: file(file), system_header(system_header) { }
std::string file;
bool system_header;
void accept(Visitor &v) override;
};
......
......@@ -148,7 +148,10 @@ void Printer::visit(Probe &probe)
void Printer::visit(Include &include)
{
std::string indent(depth_, ' ');
out_ << indent << "#include " << include.file << std::endl;
if (include.system_header)
out_ << indent << "#include <" << include.file << ">" << std::endl;
else
out_ << indent << "#include \"" << include.file << "\"" << std::endl;
}
void Printer::visit(Program &program)
......
......@@ -115,8 +115,8 @@ includes : includes include { $$ = $1; $1->push_back($2); }
| { $$ = new ast::IncludeList; }
;
include : INCLUDE STRING { $$ = new ast::Include($2); }
| INCLUDE HEADER { $$ = new ast::Include($2.substr(1, $2.size()-2)); }
include : INCLUDE STRING { $$ = new ast::Include($2, false); }
| INCLUDE HEADER { $$ = new ast::Include($2.substr(1, $2.size()-2), true); }
;
probes : probes probe { $$ = $1; $1->push_back($2); }
......
......@@ -304,7 +304,7 @@ TEST(Parser, include)
{
test("#include <stdio.h> kprobe:sys_read { @x = 1 }",
"Program\n"
" #include stdio.h\n"
" #include <stdio.h>\n"
" kprobe:sys_read\n"
" =\n"
" map: @x\n"
......@@ -315,7 +315,7 @@ TEST(Parser, include_quote)
{
test("#include \"stdio.h\" kprobe:sys_read { @x = 1 }",
"Program\n"
" #include stdio.h\n"
" #include \"stdio.h\"\n"
" kprobe:sys_read\n"
" =\n"
" map: @x\n"
......@@ -326,9 +326,9 @@ TEST(Parser, include_multiple)
{
test("#include <stdio.h> #include \"blah\" #include <foo.h> kprobe:sys_read { @x = 1 }",
"Program\n"
" #include stdio.h\n"
" #include blah\n"
" #include foo.h\n"
" #include <stdio.h>\n"
" #include \"blah\"\n"
" #include <foo.h>\n"
" kprobe:sys_read\n"
" =\n"
" map: @x\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment