-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mostly complete parsing, list variable expansion and output generation.
- Loading branch information
Showing
22 changed files
with
1,258 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/cmake-build-debug | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- detect circular list variables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Bindings.cc -- | ||
Copyright (C) Dieter Baron | ||
The authors can be contacted at <[email protected]> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. The names of the authors may not be used to endorse or promote | ||
products derived from this software without specific prior | ||
written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "Bindings.h" | ||
|
||
|
||
#include <Exception.h> | ||
|
||
Bindings::Bindings(Tokenizer& tokenizer) { | ||
auto token = tokenizer.next(Tokenizer::Skip::WHITESPACE); | ||
if (token.type != Tokenizer::TokenType::BEGIN_SCOPE) { | ||
tokenizer.unget(token); | ||
return; | ||
} | ||
|
||
while (((token = tokenizer.next(Tokenizer::Skip::SPACE))) && token.type != Tokenizer::TokenType::END_SCOPE) { | ||
if (token.type != Tokenizer::TokenType::WORD) { | ||
throw Exception("invalid variable name"); | ||
} | ||
auto name = token.string(); | ||
token = tokenizer.next(Tokenizer::Skip::SPACE); | ||
if (token.type != Tokenizer::TokenType::ASSIGN && token.type != Tokenizer::TokenType::ASSIGN_LIST) { | ||
throw Exception("assignment expected"); | ||
} | ||
variables[name] = Variable(name, token.type == Tokenizer::TokenType::ASSIGN_LIST, tokenizer); | ||
} | ||
} | ||
|
||
|
||
void Bindings::print(std::ostream& stream, const std::string& indent) const { | ||
for (auto& pair : *this) { | ||
if (!pair.second.is_list) { | ||
stream << indent; | ||
pair.second.print_definition(stream); | ||
stream << std::endl; | ||
} | ||
} | ||
} | ||
|
||
void Bindings::process(const File& file) { | ||
for (auto& pair : variables) { | ||
pair.second.process(file); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Bindings.h -- | ||
Copyright (C) Dieter Baron | ||
The authors can be contacted at <[email protected]> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. The names of the authors may not be used to endorse or promote | ||
products derived from this software without specific prior | ||
written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef BINDINGS_H | ||
#define BINDINGS_H | ||
|
||
#include <unordered_map> | ||
|
||
#include "Variable.h" | ||
|
||
class Bindings { | ||
public: | ||
Bindings() = default; | ||
explicit Bindings(Tokenizer& tokenizer); | ||
|
||
void print(std::ostream& stream, const std::string& indent) const; | ||
void process(const File& file); | ||
void add(const std::string& name, Variable variable) {variables[name] = std::move(variable);} | ||
|
||
auto begin() { return variables.begin(); } | ||
|
||
auto end() { return variables.end(); } | ||
|
||
[[nodiscard]] auto begin() const { return variables.begin(); } | ||
|
||
[[nodiscard]] auto end() const { return variables.end(); } | ||
auto find(const std::string& name) {return variables.find(name);} | ||
auto find(const std::string& name) const {return variables.find(name);} | ||
|
||
private: | ||
std::unordered_map<std::string, Variable> variables; | ||
}; | ||
|
||
#endif // BINDINGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Build.cc -- | ||
Copyright (C) Dieter Baron | ||
The authors can be contacted at <[email protected]> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. The names of the authors may not be used to endorse or promote | ||
products derived from this software without specific prior | ||
written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "Build.h" | ||
|
||
|
||
#include "File.h" | ||
|
||
Build::Build(Tokenizer& tokenizer) { | ||
outputs = Text{ tokenizer, Tokenizer::TokenType::COLON }; | ||
inputs = Text{tokenizer, Tokenizer::TokenType::NEWLINE}; | ||
bindings = Bindings{ tokenizer }; | ||
} | ||
|
||
void Build::process(const File& file) { | ||
inputs.process(file); | ||
bindings.process(file); | ||
} | ||
|
||
void Build::process_outputs(const File& file) { | ||
outputs.process(file); | ||
} | ||
|
||
void Build::print(std::ostream& stream) const { | ||
stream << std::endl << "build " << outputs << " : " << inputs << std::endl; | ||
bindings.print(stream, " "); | ||
} | ||
|
||
std::unordered_set<std::string> Build::get_outputs() const { | ||
auto result = std::unordered_set<std::string>{}; | ||
outputs.collect_words(result); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Build.h -- | ||
Copyright (C) Dieter Baron | ||
The authors can be contacted at <[email protected]> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. The names of the authors may not be used to endorse or promote | ||
products derived from this software without specific prior | ||
written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef BUILD_H | ||
#define BUILD_H | ||
|
||
#include <unordered_set> | ||
#include <vector> | ||
|
||
#include "Bindings.h" | ||
#include "Rule.h" | ||
|
||
class Build { | ||
public: | ||
Build() = default; | ||
explicit Build(Tokenizer& tokenizer); | ||
|
||
void process(const File& file); | ||
void process_outputs(const File& file); | ||
void print(std::ostream& stream) const; | ||
|
||
[[nodiscard]] std::unordered_set<std::string> get_outputs() const; | ||
|
||
private: | ||
const Rule* rule = nullptr; | ||
std::string rule_name; | ||
Text outputs; | ||
Text inputs; | ||
Bindings bindings; | ||
}; | ||
|
||
#endif // BUILD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.