Explorar el Código

make SourceFile use BBBParser

feature/dependency-graph
Martin Dørum hace 4 años
padre
commit
d8b8167187
Se han modificado 4 ficheros con 26 adiciones y 43 borrados
  1. 7
    8
      src/BBBParser.h
  2. 14
    30
      src/SourceFile.cc
  3. 4
    4
      src/SourceFile.h
  4. 1
    1
      src/main.cc

+ 7
- 8
src/BBBParser.h Ver fichero

@@ -25,9 +25,14 @@ public:
BBBParser(std::istream &stream, int flags, int line = 1, int ch = 1):
flags_(flags), line_(line), ch_(ch), stream_(stream) {}

void parseLine(const Variables &vars, std::vector<std::string> &values);
void parse(Variables &vars);

int peek() { return stream_.peek(); }
int peek2() { stream_.get(); int ch = peek(); stream_.unget(); return ch; }
int get();
void skip(char);
void skip() { get(); }

int flags_;
int line_;
int ch_;
@@ -39,15 +44,9 @@ private:
EQUALS_PLUS,
NONE,
};

int peek() { return stream_.peek(); }
int peek2() { stream_.get(); int ch = peek(); stream_.unget(); return ch; }
int get();
Operator readOperator();
void skip(char);
void skip() { get(); }
[[noreturn]] void error(std::string);

Operator readOperator();
void skipWhitespaceLine();
void skipWhitespace();


+ 14
- 30
src/SourceFile.cc Ver fichero

@@ -4,44 +4,28 @@
#include <fstream>
#include <sstream>

static bool startsWith(const std::string &a, const std::string &b, std::string &after) {
if (a.size() < b.size())
return false;

for (size_t i = 0; i < b.size(); ++i) {
if (a[i] != b[i])
static bool startsWith(BBBParser &parser, const char *str) {
for (size_t i = 0; str[i] != '\0'; ++i) {
if (parser.get() != str[i])
return false;
}

after = a.substr(b.size());
return true;
}

static void parseParts(std::vector<std::string> &vec, const std::string &str) {
std::istringstream ss(str);
std::string part;
while (ss >> part) {
vec.push_back(part);
}
}

SourceFile::SourceFile(std::string dir, std::string name):
dir_(std::move(dir)), name_(std::move(name)) {
SourceFile::SourceFile(std::string dir, std::string name, BBBParser::Variables vars):
dir_(std::move(dir)), name_(std::move(name)), vars_(std::move(vars)) {

std::ifstream file(dir_ + "/" + name_);

std::string line;
std::string content;
while (std::getline(file, line)) {
if (line.size() < 4) continue;
if (line[0] != '/' || line[1] != '/' || line[2] != '#') continue;

if (startsWith(line, "//# pkgs:", content)) {
parseParts(pkgs_, content);
} else if (startsWith(line, "//# cflags:", content)) {
parseParts(pkgs_, content);
} else if (startsWith(line, "//# ldflags:", content)) {
parseParts(pkgs_, content);
BBBParser parser(file, BBBParser::FLAG_ONE_LINE);

bool freshLine = true;
while (file.good()) {
if (freshLine && startsWith(parser, "//#bb")) {
parser.parse(vars_);
} else {
while (file.good() && parser.get() != '\n');
freshLine = true;
}
}
}

+ 4
- 4
src/SourceFile.h Ver fichero

@@ -3,14 +3,14 @@
#include <vector>
#include <string>

#include "BBBParser.h"

class SourceFile {
public:
SourceFile(std::string dir, std::string name);
SourceFile(std::string dir, std::string name, BBBParser::Variables vars);

private:
std::string dir_;
std::string name_;
std::vector<std::string> pkgs_;
std::vector<std::string> cflags_;
std::vector<std::string> ldflags_;
BBBParser::Variables vars_;
};

+ 1
- 1
src/main.cc Ver fichero

@@ -54,7 +54,7 @@ void readDir(std::string dir, std::vector<SourceFile> &sources, BBBParser::Varia
if (S_ISDIR(st.st_mode)) {
readDir(path, sources, vars);
} else {
sources.emplace_back(dir, ent);
sources.emplace_back(dir, ent, vars);
}
}
}

Cargando…
Cancelar
Guardar