|
Ninja
|
Parser for the dependency information emitted by gcc's -M flags. More...
#include <depfile_parser.h>
Public Member Functions | |
| DepfileParser (DepfileParserOptions options=DepfileParserOptions()) | |
| bool | Parse (std::string *content, std::string *err) |
| Parse an input file. More... | |
Public Attributes | |
| std::vector< StringPiece > | ins_ |
| DepfileParserOptions | options_ |
| std::vector< StringPiece > | outs_ |
Parser for the dependency information emitted by gcc's -M flags.
Definition at line 28 of file depfile_parser.h.
|
explicit |
Definition at line 23 of file depfile_parser.cc.
| bool DepfileParser::Parse | ( | std::string * | content, |
| std::string * | err | ||
| ) |
Parse an input file.
Input must be NUL-terminated. Warning: may mutate the content in-place and parsed StringPieces are pointers within it.
re2c re2c:define:YYCTYPE = "unsigned char"; re2c:define:YYCURSOR = in; re2c:define:YYLIMIT = end; re2c:define:YYMARKER = yymarker;
re2c:yyfill:enable = 0;
re2c:indent:top = 2; re2c:indent:string = " ";
nul = "\000"; newline = '\r'?'
';
'\\'* '\ ' { 2N+1 backslashes plus space -> N backslashes plus space. int len = (int)(in - start); int n = len / 2 - 1; if (out < start) memset(out, '\', n); out += n; out++ = ' '; continue; } '\\'+ ' ' { 2N backslashes plus space -> 2N backslashes, end of filename. int len = (int)(in - start); if (out < start) memset(out, '\', len - 1); out += len - 1; break; } '\'+ '#' { De-escape hash sign, but preserve other leading backslashes. int len = (int)(in - start); if (len > 2 && out < start) memset(out, '\', len - 2); out += len - 2; out++ = '#'; continue; } '\'+ ':' [\x00\x20\r
\t] { Backslash followed by : and whitespace. It is therefore normal text and not an escaped colon int len = (int)(in - start - 1); Need to shift it over if we're overwriting backslashes. if (out < start) memmove(out, start, len); out += len; if (*(in - 1) == '
') have_newline = true; break; } '\'+ ':' { De-escape colon sign, but preserve other leading backslashes. Regular expression uses lookahead to make sure that no whitespace nor EOF follows. In that case it'd be the : at the end of a target int len = (int)(in - start); if (len > 2 && out < start) memset(out, '\', len - 2); out += len - 2; out++ = ':'; continue; } '$$' { De-escape dollar character. out++ = '$'; continue; } '\'+ [^\000\r
] | [a-zA-Z0-9+?"'&,/_:.~()}{%=\x5B\x5D!\x80-\xFF-]+ { Got a span of plain text. int len = (int)(in - start); Need to shift it over if we're overwriting backslashes. if (out < start) memmove(out, start, len); out += len; continue; } nul { break; } '\' newline { A line continuation ends the current file name. break; } newline { A newline ends the current file name and the current rule. have_newline = true; break; } [^] { For any other character (e.g. whitespace), swallow it here, allowing the outer logic to loop around again. break; }
Definition at line 48 of file depfile_parser.cc.
Referenced by Builder::ExtractDeps(), ImplicitDepLoader::LoadDepFile(), and main().
| std::vector<StringPiece> DepfileParser::ins_ |
Definition at line 38 of file depfile_parser.h.
Referenced by Builder::ExtractDeps(), ImplicitDepLoader::LoadDepFile(), and Parse().
| DepfileParserOptions DepfileParser::options_ |
Definition at line 39 of file depfile_parser.h.
| std::vector<StringPiece> DepfileParser::outs_ |
Definition at line 37 of file depfile_parser.h.
Referenced by ImplicitDepLoader::LoadDepFile(), and Parse().