Skip to content

Commit

Permalink
Fixes del linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan-R0 committed Nov 15, 2020
1 parent 4d056ea commit dda718e
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 40 deletions.
20 changes: 6 additions & 14 deletions asmline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <algorithm>
#include <iostream>
#include <utility>

Asmline::Asmline()
: jumpCodes({"jmp", "ja", "jeq", "jneq", "jne", "jlt", "jle", "jgt", "jge",
Expand All @@ -18,23 +19,14 @@ bool Asmline::esCortante() {
return false;
}

std::string Asmline::getOpcode() { return this->opCode; }
std::string Asmline::getLabel() { return this->label; }
std::list<std::string> Asmline::getLabelsToJumpTo() {
return this->labelsToJump;
}
void Asmline::setLabel(std::string labelGiven) { label = labelGiven; }
void Asmline::setOpCode(std::string opCodeGiven) { opCode = opCodeGiven; }
void Asmline::setLabel(const std::string& labelGiven) { label = labelGiven; }
void Asmline::setOpCode(const std::string& opCodeGiven) {
opCode = opCodeGiven;
}
void Asmline::setLabelToJump(std::string labelToJumpGiven) {
labelsToJump.push_back(labelToJumpGiven);
}

void Asmline::setLabelsToJump(std::list<std::string> labelsToJumpGiven) {
if (!this->isJump()) return;
if (labelsToJumpGiven.size() == 1) {
labelsToJump.push_back(labelsToJumpGiven.back());
} else {
labelsToJumpGiven.pop_front();
labelsToJump = std::move(labelsToJumpGiven);
}
}
}
4 changes: 2 additions & 2 deletions asmline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Asmline {

public:
Asmline();
void setLabel(std::string labelGiven);
void setOpCode(std::string opCodeGiven);
void setLabel(const std::string& labelGiven);
void setOpCode(const std::string& opCodeGiven);
void setLabelToJump(std::string labelToJumpGiven);
std::string getOpcode();
std::string getLabel();
Expand Down
3 changes: 2 additions & 1 deletion eBPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

#include <fstream>
#include <iostream>
#include <utility>

#include "fileFountain.h"
#include "graph.h"
#include "graphFiller.h"
#include "results.h"

void EBPF::init(std::string& filename) {
void EBPF::init(const std::string& filename) {
int i = 1;
std::ifstream reader;
reader.open(filename, std::ifstream::in);
Expand Down
4 changes: 2 additions & 2 deletions eBPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class EBPF : public Thread {
Results& results;
FileFountain& fileFountain;
Graphfiller filler;
void init(std::string& filename);
void init(const std::string& filename);

public:
EBPF(Results& r, FileFountain& f);
void run();
void run() override;
void restart();
~EBPF() {}
bool hasCycle();
Expand Down
2 changes: 1 addition & 1 deletion executer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ void Executer::run(int argc, char* argv[]) {
delete it;
}
results.printResults();
}
}
5 changes: 3 additions & 2 deletions executer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class Executer {
std::vector<EBPF*> holders;

public:
Executer(char* argv[]) : numberOfThreads(strtol(argv[1], NULL, 10)) {}
explicit Executer(char* argv[])
: numberOfThreads(strtol(argv[1], NULL, 10)) {}
void run(int argc, char* argv[]);
};

#endif // EXECUTER_H_
#endif // EXECUTER_H_
3 changes: 1 addition & 2 deletions fileFountain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <algorithm>
#include <iostream>
#include <mutex>
#include <utility>

FileFountain::FileFountain(int argc, char* argv[]) {
for (int i = argc - 1; i > 1; i--) {
Expand All @@ -11,8 +12,6 @@ FileFountain::FileFountain(int argc, char* argv[]) {
}
}

int FileFountain::getNumberOfFiles() { return files.size(); }

std::string FileFountain::getNext() {
std::unique_lock<std::mutex> lock(m);
if (files.size() == 0) return "";
Expand Down
2 changes: 0 additions & 2 deletions fileFountain.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
class FileFountain {
private:
std::vector<std::string> files;
size_t toRead;
std::mutex m;

public:
FileFountain(int argc, char *argv[]);
std::string getNext();
int getNumberOfFiles();
};

#endif // FILEFOUNTAIN_H_
2 changes: 2 additions & 0 deletions graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <map>
#include <string>

typedef std::pair<int, std::list<int>> iterator_t;

class Graph {
private:
std::map<int, std::list<int>> nodes;
Expand Down
12 changes: 5 additions & 7 deletions graphFiller.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "graphFiller.h"

#include <list>
#include <string>
#include <utility>

#include "asmline.h"
#include "parser.h"

Expand All @@ -10,12 +14,6 @@ void Graphfiller::restart() {
opGraph.clear();
}

Graphfiller::Graphfiller() {
referenciasColgadas = {};
referenciasReconocidas = {};
aristaACortar = {};
}

void Graphfiller::addInstructionToGraph(std::string line, int lineNumber) {
if (line.size() == 0) return;
Asmline instruction;
Expand Down Expand Up @@ -47,4 +45,4 @@ void Graphfiller::connectLostTags() {
std::move(referenciasReconocidas[it.first]));
}
}
}
}
3 changes: 2 additions & 1 deletion graphFiller.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef GRAPHFILLER_H_
#define GRAPHFILLER_H_

#include <list>
#include <map>
#include <string>

#include "graph.h"
#include "parser.h"
Expand All @@ -15,7 +17,6 @@ class Graphfiller {
Graph opGraph;

public:
Graphfiller();
void restart();
void connectLostTags();
void addInstructionToGraph(std::string line, int lineNumber);
Expand Down
17 changes: 12 additions & 5 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static void parseSpaces(std::string* asmLine) {

void Parser::parseInstruction(std::string asmLine, Asmline& instruction) {
parseSpaces(&asmLine);

int firstDots = asmLine.find_first_of(":");
if (firstDots != -1) {
instruction.setLabel(asmLine.substr(0, firstDots));
Expand All @@ -32,12 +33,18 @@ void Parser::parseInstruction(std::string asmLine, Asmline& instruction) {

if (instruction.isJump()) {
int firstComma = asmLine.find_first_of(",");
std::string firstArg = asmLine.substr(0, firstComma);
asmLine.erase(0, firstComma + 2);
if ((firstComma = asmLine.find_first_of(",")) != -1) {
instruction.setLabelToJump(asmLine.substr(0, firstComma));
std::string secondArg;
if (firstComma != -1) {
asmLine.erase(0, firstComma + 2);
if (!asmLine.empty()) instruction.setLabelToJump(asmLine);
int secondComma = asmLine.find_first_of(",");
if (secondComma != -1) {
secondArg = asmLine.substr(0, secondComma);
asmLine.erase(0, secondComma + 2);
instruction.setLabelToJump(secondArg);
instruction.setLabelToJump(asmLine);
} else {
instruction.setLabelToJump(asmLine);
}
} else {
instruction.setLabelToJump(asmLine);
}
Expand Down
3 changes: 2 additions & 1 deletion results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

#define CORRECT " GOOD\n"
#define FAILHASCYCLES " FAIL: cycle detected\n"
#define FAILHASUNUSED " FAIL: unused instructions detected\n"

static int cmp(std::string a, std::string b) { return a < b; }
static int cmp(const std::string& a, const std::string& b) { return a < b; }

static void sort(std::vector<std::string>& v) {
std::sort(v.begin(), v.end(), cmp);
Expand Down

0 comments on commit dda718e

Please sign in to comment.