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

1158 {
1159  Success,
1160  SyntaxError,
1161  Eof
1162 };
Definition: remake.cpp:1161

Function Documentation

◆ addprefix_generator()

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

Definition at line 1303 of file remake.cpp.

1304  : gen(top.in, top.local_variables)
1305 {
1306  if (!read_words(gen, pre)) return;
1307  if (!expect_token(gen.in, Comma)) return;
1308  prej = 0;
1309  prel = pre.size();
1310  ok = true;
1311 }
static bool read_words(input_generator &in, string_list &res)
Definition: remake.cpp:1271
std::istream & in
Definition: remake.cpp:1219
static int expect_token(std::istream &in, int mask)
Definition: remake.cpp:1059
input_generator gen
Definition: remake.cpp:1294
string_list pre
Definition: remake.cpp:1295

◆ addsuffix_generator()

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

Definition at line 1359 of file remake.cpp.

1360  : gen(top.in, top.local_variables)
1361 {
1362  if (!read_words(gen, suf)) return;
1363  if (!expect_token(gen.in, Comma)) return;
1364  sufj = 0;
1365  sufl = suf.size();
1366  ok = true;
1367 }
static bool read_words(input_generator &in, string_list &res)
Definition: remake.cpp:1271
input_generator gen
Definition: remake.cpp:1350
std::istream & in
Definition: remake.cpp:1219
static int expect_token(std::istream &in, int mask)
Definition: remake.cpp:1059
string_list suf
Definition: remake.cpp:1351

◆ get_function()

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

Return a generator for function name.

Definition at line 1399 of file remake.cpp.

1400 {
1401  skip_spaces(in.in);
1402  generator *g = NULL;
1403  bool ok = false;
1404  if (name == "addprefix") g = new addprefix_generator(in, ok);
1405  else if (name == "addsuffix") g = new addsuffix_generator(in, ok);
1406  if (!g || ok) return g;
1407  delete g;
1408  return NULL;
1409 }
static void skip_spaces(std::istream &in)
Definition: remake.cpp:1009

Referenced by input_generator::next().

◆ next() [1/4]

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

Implements generator.

Definition at line 1203 of file remake.cpp.

1204 {
1205  if (vcur != vend)
1206  {
1207  res = *vcur;
1208  ++vcur;
1209  return Success;
1210  }
1211  return Eof;
1212 }
string_list::const_iterator vend
Definition: remake.cpp:1179
Definition: remake.cpp:1161
string_list::const_iterator vcur
Definition: remake.cpp:1179

◆ next() [2/4]

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

Definition at line 1231 of file remake.cpp.

1232 {
1233  if (nested)
1234  {
1235  restart:
1236  input_status s = nested->next(res);
1237  if (s == Success) return Success;
1238  delete nested;
1239  nested = NULL;
1240  if (s == SyntaxError) return SyntaxError;
1241  }
1242  if (done) return Eof;
1243  if (earliest_exit) done = true;
1244  switch (expect_token(in, Word | Dollarpar))
1245  {
1246  case Word:
1247  res = read_word(in, false);
1248  return Success;
1249  case Dollarpar:
1250  {
1251  std::string name = read_word(in, false);
1252  if (name.empty()) return SyntaxError;
1253  if (expect_token(in, Rightpar))
1255  else
1256  {
1257  nested = get_function(*this, name);
1258  if (!nested) return SyntaxError;
1259  }
1260  goto restart;
1261  }
1262  default:
1263  return Eof;
1264  }
1265 }
static generator * get_function(input_generator const &, std::string const &)
Definition: remake.cpp:1399
static std::string read_word(std::istream &in, bool detect_equal=true)
Definition: remake.cpp:1105
Definition: remake.cpp:1161
input_status
Definition: remake.cpp:1157
std::istream & in
Definition: remake.cpp:1219
generator * nested
Definition: remake.cpp:1220
static int expect_token(std::istream &in, int mask)
Definition: remake.cpp:1059
virtual input_status next(std::string &)=0
variable_map const * local_variables
Definition: remake.cpp:1221
bool earliest_exit
Definition: remake.cpp:1222

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

1314 {
1315  if (prej)
1316  {
1317  produce:
1318  if (prej == prel)
1319  {
1320  res = *prei + suf;
1321  prej = 0;
1322  }
1323  else
1324  {
1325  res = *prei++;
1326  ++prej;
1327  }
1328  return Success;
1329  }
1330  switch (gen.next(res))
1331  {
1332  case Success:
1333  if (!prel) return Success;
1334  prei = pre.begin();
1335  prej = 1;
1336  suf = res;
1337  goto produce;
1338  case Eof:
1339  return expect_token(gen.in, Rightpar) ? Eof : SyntaxError;
1340  default:
1341  return SyntaxError;
1342  }
1343 }
input_status next(std::string &)
Definition: remake.cpp:1231
Definition: remake.cpp:1161
std::istream & in
Definition: remake.cpp:1219
string_list::const_iterator prei
Definition: remake.cpp:1296
static int expect_token(std::istream &in, int mask)
Definition: remake.cpp:1059
input_generator gen
Definition: remake.cpp:1294
std::string suf
Definition: remake.cpp:1298
string_list pre
Definition: remake.cpp:1295

◆ next() [4/4]

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

Implements generator.

Definition at line 1369 of file remake.cpp.

1370 {
1371  if (sufj)
1372  {
1373  if (sufj != sufl)
1374  {
1375  res = *sufi++;
1376  ++sufj;
1377  return Success;
1378  }
1379  sufj = 0;
1380  }
1381  switch (gen.next(res))
1382  {
1383  case Success:
1384  if (!sufl) return Success;
1385  sufi = suf.begin();
1386  sufj = 1;
1387  res += *sufi++;
1388  return Success;
1389  case Eof:
1390  return expect_token(gen.in, Rightpar) ? Eof : SyntaxError;
1391  default:
1392  return SyntaxError;
1393  }
1394 }
input_status next(std::string &)
Definition: remake.cpp:1231
string_list::const_iterator sufi
Definition: remake.cpp:1352
Definition: remake.cpp:1161
input_generator gen
Definition: remake.cpp:1350
std::istream & in
Definition: remake.cpp:1219
static int expect_token(std::istream &in, int mask)
Definition: remake.cpp:1059
string_list suf
Definition: remake.cpp:1351

◆ 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 1271 of file remake.cpp.

1272 {
1273  while (true)
1274  {
1275  res.push_back(std::string());
1276  input_status s = in.next(res.back());
1277  if (s == Success) continue;
1278  res.pop_back();
1279  return s == Eof;
1280  }
1281 }
input_status next(std::string &)
Definition: remake.cpp:1231
Definition: remake.cpp:1161
input_status
Definition: remake.cpp:1157

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

1284 {
1285  input_generator gen(in, NULL);
1286  return read_words(gen, res);
1287 }
static bool read_words(input_generator &in, string_list &res)
Definition: remake.cpp:1271

◆ variable_generator()

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

Definition at line 1184 of file remake.cpp.

1185  : name(n)
1186 {
1187  if (local_variables)
1188  {
1189  variable_map::const_iterator i = local_variables->find(name);
1190  if (i != local_variables->end())
1191  {
1192  vcur = i->second.begin();
1193  vend = i->second.end();
1194  return;
1195  }
1196  }
1197  variable_map::const_iterator i = variables.find(name);
1198  if (i == variables.end()) return;
1199  vcur = i->second.begin();
1200  vend = i->second.end();
1201 }
static variable_map variables
Definition: remake.cpp:604
std::string name
Definition: remake.cpp:1178
string_list::const_iterator vend
Definition: remake.cpp:1179
string_list::const_iterator vcur
Definition: remake.cpp:1179