Remake
Loading...
Searching...
No Matches
Token streams

Classes

struct  generator
struct  variable_generator
struct  input_generator
struct  addprefix_generator
struct  addsuffix_generator

Enumerations

enum  input_status { Success , SyntaxError , Eof }

Functions

static generatorget_function (input_generator const &, std::string const &)
static bool read_words (input_generator &in, string_list &res)
static bool read_words (std::istream &in, string_list &res)
 variable_generator::variable_generator (std::string const &, variable_map const *)
input_status variable_generator::next (std::string &)
input_status input_generator::next (std::string &)
 addprefix_generator::addprefix_generator (input_generator const &, bool &)
input_status addprefix_generator::next (std::string &)
 addsuffix_generator::addsuffix_generator (input_generator const &, bool &)
input_status addsuffix_generator::next (std::string &)

Detailed Description

Enumeration Type Documentation

◆ input_status

Possible results from word producers.

Enumerator
Success 
SyntaxError 
Eof 

Definition at line 1172 of file remake.cpp.

1173{
1174 Success,
1176 Eof
1177};
@ SyntaxError
Definition remake.cpp:1175
@ Eof
Definition remake.cpp:1176
@ Success
Definition remake.cpp:1174

Function Documentation

◆ addprefix_generator()

addprefix_generator::addprefix_generator ( input_generator const & top,
bool & ok )

Definition at line 1318 of file remake.cpp.

1319 : gen(top.in, top.local_variables)
1320{
1321 if (!read_words(gen, pre)) return;
1322 if (!expect_token(gen.in, Comma)) return;
1323 prej = 0;
1324 prel = pre.size();
1325 ok = true;
1326}
static int expect_token(std::istream &in, int mask)
Definition remake.cpp:1074
@ Comma
Definition remake.cpp:1063
static bool read_words(input_generator &in, string_list &res)
Definition remake.cpp:1286
input_generator gen
Definition remake.cpp:1309
string_list pre
Definition remake.cpp:1310

◆ addsuffix_generator()

addsuffix_generator::addsuffix_generator ( input_generator const & top,
bool & ok )

Definition at line 1374 of file remake.cpp.

1375 : gen(top.in, top.local_variables)
1376{
1377 if (!read_words(gen, suf)) return;
1378 if (!expect_token(gen.in, Comma)) return;
1379 sufj = 0;
1380 sufl = suf.size();
1381 ok = true;
1382}
string_list suf
Definition remake.cpp:1366
input_generator gen
Definition remake.cpp:1365

◆ get_function()

generator * get_function ( input_generator const & in,
std::string const & name )
static

Return a generator for function name.

Definition at line 1414 of file remake.cpp.

1415{
1416 skip_spaces(in.in);
1417 generator *g = NULL;
1418 bool ok = false;
1419 if (name == "addprefix") g = new addprefix_generator(in, ok);
1420 else if (name == "addsuffix") g = new addsuffix_generator(in, ok);
1421 if (!g || ok) return g;
1422 delete g;
1423 return NULL;
1424}
static void skip_spaces(std::istream &in)
Definition remake.cpp:1024

Referenced by input_generator::next().

◆ next() [1/4]

input_status addprefix_generator::next ( std::string & res)
virtual

Implements generator.

Definition at line 1328 of file remake.cpp.

1329{
1330 if (prej)
1331 {
1332 produce:
1333 if (prej == prel)
1334 {
1335 res = *prei + suf;
1336 prej = 0;
1337 }
1338 else
1339 {
1340 res = *prei++;
1341 ++prej;
1342 }
1343 return Success;
1344 }
1345 switch (gen.next(res))
1346 {
1347 case Success:
1348 if (!prel) return Success;
1349 prei = pre.begin();
1350 prej = 1;
1351 suf = res;
1352 goto produce;
1353 case Eof:
1354 return expect_token(gen.in, Rightpar) ? Eof : SyntaxError;
1355 default:
1356 return SyntaxError;
1357 }
1358}
@ Rightpar
Definition remake.cpp:1062
string_list::const_iterator prei
Definition remake.cpp:1311
std::string suf
Definition remake.cpp:1313

◆ next() [2/4]

input_status addsuffix_generator::next ( std::string & res)
virtual

Implements generator.

Definition at line 1384 of file remake.cpp.

1385{
1386 if (sufj)
1387 {
1388 if (sufj != sufl)
1389 {
1390 res = *sufi++;
1391 ++sufj;
1392 return Success;
1393 }
1394 sufj = 0;
1395 }
1396 switch (gen.next(res))
1397 {
1398 case Success:
1399 if (!sufl) return Success;
1400 sufi = suf.begin();
1401 sufj = 1;
1402 res += *sufi++;
1403 return Success;
1404 case Eof:
1405 return expect_token(gen.in, Rightpar) ? Eof : SyntaxError;
1406 default:
1407 return SyntaxError;
1408 }
1409}
string_list::const_iterator sufi
Definition remake.cpp:1367

◆ next() [3/4]

input_status input_generator::next ( std::string & res)

Definition at line 1246 of file remake.cpp.

1247{
1248 if (nested)
1249 {
1250 restart:
1251 input_status s = nested->next(res);
1252 if (s == Success) return Success;
1253 delete nested;
1254 nested = NULL;
1255 if (s == SyntaxError) return SyntaxError;
1256 }
1257 if (done) return Eof;
1258 if (earliest_exit) done = true;
1259 switch (expect_token(in, Word | Dollarpar))
1260 {
1261 case Word:
1262 res = read_word(in, false);
1263 return Success;
1264 case Dollarpar:
1265 {
1266 std::string name = read_word(in, false);
1267 if (name.empty()) return SyntaxError;
1268 if (expect_token(in, Rightpar))
1269 nested = new variable_generator(name, local_variables);
1270 else
1271 {
1272 nested = get_function(*this, name);
1273 if (!nested) return SyntaxError;
1274 }
1275 goto restart;
1276 }
1277 default:
1278 return Eof;
1279 }
1280}
static std::string read_word(std::istream &in, bool detect_equal=true)
Definition remake.cpp:1120
@ Word
Definition remake.cpp:1058
@ Dollarpar
Definition remake.cpp:1061
static generator * get_function(input_generator const &, std::string const &)
Definition remake.cpp:1414
input_status
Definition remake.cpp:1173
std::istream & in
Definition remake.cpp:1234
generator * nested
Definition remake.cpp:1235
variable_map const * local_variables
Definition remake.cpp:1236

Referenced by prepare_script(), and read_words().

◆ next() [4/4]

input_status variable_generator::next ( std::string & res)
virtual

Implements generator.

Definition at line 1218 of file remake.cpp.

1219{
1220 if (vcur != vend)
1221 {
1222 res = *vcur;
1223 ++vcur;
1224 return Success;
1225 }
1226 return Eof;
1227}
string_list::const_iterator vend
Definition remake.cpp:1194
string_list::const_iterator vcur
Definition remake.cpp:1194

◆ read_words() [1/2]

bool read_words ( input_generator & in,
string_list & res )
static

Read a list of words from an input generator.

Returns
false if a syntax error was encountered.

Definition at line 1286 of file remake.cpp.

1287{
1288 while (true)
1289 {
1290 res.push_back(std::string());
1291 input_status s = in.next(res.back());
1292 if (s == Success) continue;
1293 res.pop_back();
1294 return s == Eof;
1295 }
1296}
input_status next(std::string &)
Definition remake.cpp:1246

Referenced by addprefix_generator::addprefix_generator(), addsuffix_generator::addsuffix_generator(), load_dependencies(), load_rule(), load_rules(), main(), and read_words().

◆ read_words() [2/2]

bool read_words ( std::istream & in,
string_list & res )
static

Definition at line 1298 of file remake.cpp.

1299{
1300 input_generator gen(in, NULL);
1301 return read_words(gen, res);
1302}

◆ variable_generator()

variable_generator::variable_generator ( std::string const & n,
variable_map const * local_variables )

Definition at line 1199 of file remake.cpp.

1200 : name(n)
1201{
1202 if (local_variables)
1203 {
1204 variable_map::const_iterator i = local_variables->find(name);
1205 if (i != local_variables->end())
1206 {
1207 vcur = i->second.begin();
1208 vend = i->second.end();
1209 return;
1210 }
1211 }
1212 variable_map::const_iterator i = variables.find(name);
1213 if (i == variables.end()) return;
1214 vcur = i->second.begin();
1215 vend = i->second.end();
1216}
static variable_map variables
Definition remake.cpp:617
std::string name
Definition remake.cpp:1193