Remake
Classes | Enumerations | Functions
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 1174 of file remake.cpp.

1175 {
1176  Success,
1177  SyntaxError,
1178  Eof
1179 };

Function Documentation

◆ addprefix_generator()

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

Definition at line 1320 of file remake.cpp.

1321  : gen(top.in, top.local_variables)
1322 {
1323  if (!read_words(gen, pre)) return;
1324  if (!expect_token(gen.in, Comma)) return;
1325  prej = 0;
1326  prel = pre.size();
1327  ok = true;
1328 }

◆ addsuffix_generator()

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

Definition at line 1376 of file remake.cpp.

1377  : gen(top.in, top.local_variables)
1378 {
1379  if (!read_words(gen, suf)) return;
1380  if (!expect_token(gen.in, Comma)) return;
1381  sufj = 0;
1382  sufl = suf.size();
1383  ok = true;
1384 }

◆ get_function()

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

Return a generator for function name.

Definition at line 1416 of file remake.cpp.

1417 {
1418  skip_spaces(in.in);
1419  generator *g = NULL;
1420  bool ok = false;
1421  if (name == "addprefix") g = new addprefix_generator(in, ok);
1422  else if (name == "addsuffix") g = new addsuffix_generator(in, ok);
1423  if (!g || ok) return g;
1424  delete g;
1425  return NULL;
1426 }

Referenced by input_generator::next().

◆ next() [1/4]

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

Implements generator.

Definition at line 1220 of file remake.cpp.

1221 {
1222  if (vcur != vend)
1223  {
1224  res = *vcur;
1225  ++vcur;
1226  return Success;
1227  }
1228  return Eof;
1229 }

◆ next() [2/4]

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

Definition at line 1248 of file remake.cpp.

1249 {
1250  if (nested)
1251  {
1252  restart:
1253  input_status s = nested->next(res);
1254  if (s == Success) return Success;
1255  delete nested;
1256  nested = NULL;
1257  if (s == SyntaxError) return SyntaxError;
1258  }
1259  if (done) return Eof;
1260  if (earliest_exit) done = true;
1261  switch (expect_token(in, Word | Dollarpar))
1262  {
1263  case Word:
1264  res = read_word(in, false);
1265  return Success;
1266  case Dollarpar:
1267  {
1268  std::string name = read_word(in, false);
1269  if (name.empty()) return SyntaxError;
1270  if (expect_token(in, Rightpar))
1272  else
1273  {
1274  nested = get_function(*this, name);
1275  if (!nested) return SyntaxError;
1276  }
1277  goto restart;
1278  }
1279  default:
1280  return Eof;
1281  }
1282 }

Referenced by addprefix_generator::next(), addsuffix_generator::next(), prepare_script(), and read_words().

◆ next() [3/4]

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

Implements generator.

Definition at line 1330 of file remake.cpp.

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

◆ next() [4/4]

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

Implements generator.

Definition at line 1386 of file remake.cpp.

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

◆ read_words() [1/2]

static 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 1288 of file remake.cpp.

1289 {
1290  while (true)
1291  {
1292  res.push_back(std::string());
1293  input_status s = in.next(res.back());
1294  if (s == Success) continue;
1295  res.pop_back();
1296  return s == Eof;
1297  }
1298 }

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

◆ read_words() [2/2]

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

Definition at line 1300 of file remake.cpp.

1301 {
1302  input_generator gen(in, NULL);
1303  return read_words(gen, res);
1304 }

◆ variable_generator()

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

Definition at line 1201 of file remake.cpp.

1202  : name(n)
1203 {
1204  if (local_variables)
1205  {
1206  variable_map::const_iterator i = local_variables->find(name);
1207  if (i != local_variables->end())
1208  {
1209  vcur = i->second.begin();
1210  vend = i->second.end();
1211  return;
1212  }
1213  }
1214  variable_map::const_iterator i = variables.find(name);
1215  if (i == variables.end()) return;
1216  vcur = i->second.begin();
1217  vend = i->second.end();
1218 }
variable_generator::name
std::string name
Definition: remake.cpp:1195
input_generator::next
input_status next(std::string &)
Definition: remake.cpp:1248
generator
Definition: remake.cpp:1184
variable_generator
Definition: remake.cpp:1193
input_status
input_status
Definition: remake.cpp:1174
input_generator
Definition: remake.cpp:1234
read_words
static bool read_words(input_generator &in, string_list &res)
Definition: remake.cpp:1288
addprefix_generator::prej
size_t prej
Definition: remake.cpp:1314
variable_generator::vend
string_list::const_iterator vend
Definition: remake.cpp:1196
input_generator::done
bool done
Definition: remake.cpp:1239
generator::next
virtual input_status next(std::string &)=0
Comma
@ Comma
Definition: remake.cpp:1065
read_word
static std::string read_word(std::istream &in, bool detect_equal=true)
Definition: remake.cpp:1122
input_generator::local_variables
const variable_map * local_variables
Definition: remake.cpp:1238
Dollarpar
@ Dollarpar
Definition: remake.cpp:1063
addprefix_generator::gen
input_generator gen
Definition: remake.cpp:1311
addprefix_generator::suf
std::string suf
Definition: remake.cpp:1315
addsuffix_generator
Definition: remake.cpp:1365
Success
@ Success
Definition: remake.cpp:1176
addsuffix_generator::sufi
string_list::const_iterator sufi
Definition: remake.cpp:1369
input_generator::in
std::istream & in
Definition: remake.cpp:1236
variable_generator::vcur
string_list::const_iterator vcur
Definition: remake.cpp:1196
addsuffix_generator::suf
string_list suf
Definition: remake.cpp:1368
variables
static variable_map variables
Definition: remake.cpp:619
Word
@ Word
Definition: remake.cpp:1060
addprefix_generator::prei
string_list::const_iterator prei
Definition: remake.cpp:1313
SyntaxError
@ SyntaxError
Definition: remake.cpp:1177
Eof
@ Eof
Definition: remake.cpp:1178
addsuffix_generator::sufl
size_t sufl
Definition: remake.cpp:1370
get_function
static generator * get_function(input_generator const &, std::string const &)
Definition: remake.cpp:1416
input_generator::nested
generator * nested
Definition: remake.cpp:1237
expect_token
static int expect_token(std::istream &in, int mask)
Definition: remake.cpp:1076
Rightpar
@ Rightpar
Definition: remake.cpp:1064
skip_spaces
static void skip_spaces(std::istream &in)
Definition: remake.cpp:1026
addprefix_generator::prel
size_t prel
Definition: remake.cpp:1314
input_generator::earliest_exit
bool earliest_exit
Definition: remake.cpp:1239
addsuffix_generator::sufj
size_t sufj
Definition: remake.cpp:1370
addprefix_generator
Definition: remake.cpp:1309
addsuffix_generator::gen
input_generator gen
Definition: remake.cpp:1367
addprefix_generator::pre
string_list pre
Definition: remake.cpp:1312