Skip to content

Commit

Permalink
Improve Game, Egolib, and Migrator
Browse files Browse the repository at this point in the history
All:
- Update submodule reference to Idlib, update for changes to Idlib

Migrator:
- Add dependency to Idlib
- Rename "transformers" and "validators" to "migrators"
- Add more migrators
  • Loading branch information
michaelheilmann committed Jun 2, 2017
1 parent 1fcf68c commit 7e6ddb5
Show file tree
Hide file tree
Showing 34 changed files with 693 additions and 104 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export PREFIX EGO_CXXFLAGS EGO_LDFLAGS IDLIB_TARGET EGOLIB_TARGET EGO_TARGET CAR

all: idlib egolib egoboo cartman egotool

idlib: external_lua
idlib:
${MAKE} -C $(IDLIB_DIR)

egolib: idlib
egolib: idlib external_lua
${MAKE} -C $(EGOLIB_DIR)

egoboo: egolib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ ConfigFileToken::ConfigFileToken
const id::location& startLocation,
const std::string& lexeme
) :
id::token<ConfigFileTokenKind>(kind, startLocation, lexeme)
id::token<ConfigFileTokenKind, ConfigFileTokenKind::Unknown>(kind, startLocation, lexeme)
{}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "egolib/FileFormats/ConfigFile/ConfigFileTokenKind.hpp"

class ConfigFileToken : public id::token<ConfigFileTokenKind>
class ConfigFileToken : public id::token<ConfigFileTokenKind, ConfigFileTokenKind::Unknown>
{
public:
ConfigFileToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/// @brief The kinds of tokens in a configuration file.
enum class ConfigFileTokenKind
{
/// @brief Unknown.
Unknown = 0,
/// @brief A name.
Name,
/// @brief A qualified name.
Expand Down
2 changes: 1 addition & 1 deletion egolib/src/egolib/FileFormats/SpawnFile/SpawnFileToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ SpawnFileToken::SpawnFileToken
const id::location& startLocation,
const std::string& lexeme
) :
id::token<SpawnFileTokenKind>(kind, startLocation, lexeme)
id::token<SpawnFileTokenKind, SpawnFileTokenKind::Unknown>(kind, startLocation, lexeme)
{}
2 changes: 1 addition & 1 deletion egolib/src/egolib/FileFormats/SpawnFile/SpawnFileToken.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "egolib/FileFormats/SpawnFile/SpawnFileTokenKind.hpp"

class SpawnFileToken : public id::token<SpawnFileTokenKind>
class SpawnFileToken : public id::token<SpawnFileTokenKind, SpawnFileTokenKind::Unknown>
{
public:
SpawnFileToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/// @brief The kinds of tokens in a spawn file.
enum class SpawnFileTokenKind
{
/// @brief Unknown.
Unknown = 0,
/// @brief Start of input.
StartOfInput,
/// @brief A commentary.
Expand Down
6 changes: 3 additions & 3 deletions egolib/src/egolib/InputControl/ModifierKeys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ enum class ModifierKeys : int {

} // namespace Ego

namespace Id {
namespace id {

/// 17.5.2.1.3 [bitmask.types] of the C++ Standard:
/// Bitmask types shall provide definitions for the operators |, &, ^, ~, |=, &= and ^= with the expected semantics.
Expand All @@ -74,8 +74,8 @@ namespace Id {
//// struct enable_bitmask_operators<T> { static constexpr bool enable = true; }
/// @endcode
template <>
struct EnableBitmaskOperators<Ego::ModifierKeys> {
struct enable_bitmask_operators<Ego::ModifierKeys> {
static constexpr bool enable=true;
};

} // namespace Id
} // namespace id
8 changes: 4 additions & 4 deletions egolib/src/egolib/Script/DDLToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ namespace Ego {
namespace Script {

DDLToken::DDLToken(DDLTokenKind kind, const id::location& startLocation, const std::string& lexeme)
: id::token<DDLTokenKind>(kind, startLocation, lexeme)
: id::token<DDLTokenKind, DDLTokenKind::Unknown>(kind, startLocation, lexeme)
{}

DDLToken::DDLToken(const DDLToken& other)
: id::token<DDLTokenKind>(other)
: id::token<DDLTokenKind, DDLTokenKind::Unknown>(other)
{}

DDLToken::DDLToken(DDLToken&& other)
: id::token<DDLTokenKind>(std::move(other))
: id::token<DDLTokenKind, DDLTokenKind::Unknown>(std::move(other))
{}

DDLToken& DDLToken::operator=(DDLToken other)
Expand All @@ -49,7 +49,7 @@ std::ostream& operator<<(std::ostream& os, const DDLToken& token)
{
os << "ddl token" << std::endl;
os << "{" << std::endl;
os << " " << "kind = " << token.get_kind() << "," << std::endl;
os << " " << "category = " << token.category() << "," << std::endl;
os << " " << "lexeme = " << token.get_lexeme() << "," << std::endl;
os << " " << "start location = " << token.get_start_location().file_name() << ":" << token.get_start_location().line_number() << "," << std::endl;
os << "}" << std::endl;
Expand Down
6 changes: 4 additions & 2 deletions egolib/src/egolib/Script/DDLToken.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace Ego {
namespace Script {

/// @brief A token of the DDL (Data Definition Language) of EgoScript.
struct DDLToken : public id::token<DDLTokenKind>
/// @todo Default token kind should be DDLTokenKind::Error.
struct DDLToken : public id::token<DDLTokenKind, DDLTokenKind::Unknown>
{
public:
/// @brief Construct this token with the specified values.
Expand All @@ -54,7 +55,8 @@ struct DDLToken : public id::token<DDLTokenKind>
friend void swap(DDLToken& x, DDLToken& y)
{
using std::swap;
swap(static_cast<id::token<DDLTokenKind>&>(x), static_cast<id::token<DDLTokenKind>&>(y));
swap(static_cast<id::token<DDLTokenKind, DDLTokenKind::Unknown>&>(x),
static_cast<id::token<DDLTokenKind, DDLTokenKind::Unknown>&>(y));
}

/// @brief Overloaded &lt;&lt; operator for a token.
Expand Down
3 changes: 3 additions & 0 deletions egolib/src/egolib/Script/DDLTokenKind.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// @brief Unknown.
Define(Unknown, "<unknown>")

/// @brief An integer number literal.
Define(Integer, "<integer literal>")

Expand Down
14 changes: 7 additions & 7 deletions egolib/src/egolib/Script/PDLToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ namespace Ego {
namespace Script {

PDLToken::PDLToken()
: id::token<PDLTokenKind>(PDLTokenKind::Unknown, id::location("<unknown>", 1), std::string()), m_endLocation("<unknown>", 1), m_value(0)
: id::token<PDLTokenKind,PDLTokenKind::Unknown>(PDLTokenKind::Unknown, id::location("<unknown>", 1), std::string()), m_endLocation("<unknown>", 1), m_value(0)
{}

PDLToken::PDLToken(PDLTokenKind kind, const id::location& startLocation,
const id::location& endLocation, const std::string& lexeme)
: id::token<PDLTokenKind>(kind, startLocation, lexeme), m_endLocation(endLocation), m_value(0)
: id::token<PDLTokenKind, PDLTokenKind::Unknown>(kind, startLocation, lexeme), m_endLocation(endLocation), m_value(0)
{}

PDLToken::PDLToken(const PDLToken& other)
: id::token<PDLTokenKind>(other), m_endLocation(other.m_endLocation), m_value(other.m_value)
: id::token<PDLTokenKind, PDLTokenKind::Unknown>(other), m_endLocation(other.m_endLocation), m_value(other.m_value)
{}

PDLToken::PDLToken(PDLToken&& other)
: id::token<PDLTokenKind>(std::move(other)), m_endLocation(std::move(other.m_endLocation)), m_value(std::move(other.m_value))
: id::token<PDLTokenKind, PDLTokenKind::Unknown>(std::move(other)), m_endLocation(std::move(other.m_endLocation)), m_value(std::move(other.m_value))
{}

PDLToken::~PDLToken()
Expand All @@ -61,7 +61,7 @@ bool PDLToken::isOperator() const

bool PDLToken::isAssignOperator() const
{
return is(PDLTokenKind::Assign);
return is_one_of(PDLTokenKind::Assign);
}

bool PDLToken::isLiteral() const
Expand All @@ -74,7 +74,7 @@ bool PDLToken::isLiteral() const

bool PDLToken::isConstant() const
{
return is(PDLTokenKind::Constant);
return is_one_of(PDLTokenKind::Constant);
}

PDLToken& PDLToken::operator=(PDLToken other)
Expand All @@ -87,7 +87,7 @@ std::ostream& operator<<(std::ostream& os, const PDLToken& token)
{
os << "pdl token" << std::endl;
os << "{" << std::endl;
os << " " << "kind = " << token.get_kind() << "," << std::endl;
os << " " << "category = " << token.category() << "," << std::endl;
os << " " << "lexeme = " << token.get_lexeme() << "," << std::endl;
os << " " << "start location = " << token.get_start_location().file_name() << ":" << token.get_start_location().line_number() << "," << std::endl;
os << " " << "end location = " << token.getEndLocation().file_name() << ":" << token.getEndLocation().line_number() << "," << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions egolib/src/egolib/Script/PDLToken.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Ego {
namespace Script {

/// @brief A token of the PDL (Program Definition Language) of EgoScript.
struct PDLToken : public id::token<PDLTokenKind>
struct PDLToken : public id::token<PDLTokenKind, PDLTokenKind::Unknown>
{
private:
/// @brief The end location of this token.
Expand Down Expand Up @@ -71,7 +71,7 @@ struct PDLToken : public id::token<PDLTokenKind>
friend void swap(PDLToken& x, PDLToken& y)
{
using std::swap;
swap(static_cast<id::token<PDLTokenKind>&>(x), static_cast<id::token<PDLTokenKind>&>(y));
swap(static_cast<id::token<PDLTokenKind, PDLTokenKind::Unknown>&>(x), static_cast<id::token<PDLTokenKind, PDLTokenKind::Unknown>&>(y));
swap(x.m_endLocation, y.m_endLocation);
swap(x.m_value, y.m_value);
}
Expand Down
40 changes: 20 additions & 20 deletions game/src/game/script_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ Ego::Script::PDLToken line_scanner_state_t::scanOperator()
Ego::Script::PDLToken parser_state_t::parse_indention(script_info_t& script, line_scanner_state_t& state)
{
auto source = state.scanWhiteSpaces();
if (source.get_kind() != Ego::Script::PDLTokenKind::Whitespace)
if (source.category() != Ego::Script::PDLTokenKind::Whitespace)
{
throw id::runtime_error(__FILE__, __LINE__, "internal error");
}
Expand Down Expand Up @@ -604,7 +604,7 @@ Ego::Script::PDLToken parser_state_t::parse_token(ObjectProfile *ppro, script_in
if (state.isDoubleQuote())
{
auto token = state.scanStringOrReference();
if (token.get_kind() == Ego::Script::PDLTokenKind::ReferenceLiteral)
if (token.category() == Ego::Script::PDLTokenKind::ReferenceLiteral)
{
// If it is a profile reference.

Expand Down Expand Up @@ -648,13 +648,13 @@ Ego::Script::PDLToken parser_state_t::parse_token(ObjectProfile *ppro, script_in
<< " - \n`" << _lineBuffer.toString() << "`" << Log::EndOfEntry;
Log::get() << e;
}
token.set_kind(Ego::Script::PDLTokenKind::Constant);
token.category(Ego::Script::PDLTokenKind::Constant);
}
else
{
// Add the string as a message message to the available messages of the object.
token.setValue(ppro->addMessage(token.get_lexeme(), true));
token.set_kind(Ego::Script::PDLTokenKind::Constant);
token.category(Ego::Script::PDLTokenKind::Constant);
// Emit a warning that the string is empty.
Ego::Script::CLogEntry e(Log::Level::Message, __FILE__, __LINE__, __FUNCTION__, token.get_start_location());
e << "empty string literal\n" << Log::EndOfEntry;
Expand All @@ -663,7 +663,7 @@ Ego::Script::PDLToken parser_state_t::parse_token(ObjectProfile *ppro, script_in
return token;
} else if (state.isOperator()) {
auto token = state.scanOperator();
switch (token.get_kind())
switch (token.category())
{
case Ego::Script::PDLTokenKind::Plus: token.setValue(Ego::Script::ScriptOperators::OPADD); break;
case Ego::Script::PDLTokenKind::Minus: token.setValue(Ego::Script::ScriptOperators::OPSUB); break;
Expand All @@ -679,13 +679,13 @@ Ego::Script::PDLToken parser_state_t::parse_token(ObjectProfile *ppro, script_in
return token;
} else if (state.is('[')) {
auto token = state.scanIDSZ();
token.set_kind(Ego::Script::PDLTokenKind::Constant);
token.category(Ego::Script::PDLTokenKind::Constant);
IDSZ2 idsz = IDSZ2(token.get_lexeme());
token.setValue(idsz.toUint32());
return token;
} else if (state.isDigit()) {
auto token = state.scanNumericLiteral();
token.set_kind(Ego::Script::PDLTokenKind::Constant);
token.category(Ego::Script::PDLTokenKind::Constant);
int temporary;
sscanf(token.get_lexeme().c_str(), "%d", &temporary);
token.setValue(temporary);
Expand All @@ -699,7 +699,7 @@ Ego::Script::PDLToken parser_state_t::parse_token(ObjectProfile *ppro, script_in
throw id::compilation_error(__FILE__, __LINE__, id::compilation_error_kind::lexical, state.getLocation(), "not an opcode");
}
token.setValue((*it).iValue);
token.set_kind((*it)._kind);
token.category((*it)._kind);
return token;
} else {
throw id::compilation_error(__FILE__, __LINE__, id::compilation_error_kind::lexical, state.getLocation(), "unexpected symbol");
Expand All @@ -712,19 +712,19 @@ void parser_state_t::emit_opcode(const Ego::Script::PDLToken& token, const BIT_F
BIT_FIELD loc_highbits = highbits;

// Emit the opcode.
if (Ego::Script::PDLTokenKind::Constant == token.get_kind())
if (Ego::Script::PDLTokenKind::Constant == token.category())
{
loc_highbits |= Instruction::FUNCTIONBITS;
auto constantIndex = script._instructions.getConstantPool().getOrCreateConstant(token.getValue());
script._instructions.append(Instruction(loc_highbits | constantIndex));
}
else if (Ego::Script::PDLTokenKind::Function == token.get_kind())
else if (Ego::Script::PDLTokenKind::Function == token.category())
{
loc_highbits |= Instruction::FUNCTIONBITS;
auto constantIndex = script._instructions.getConstantPool().getOrCreateConstant(token.getValue());
script._instructions.append(Instruction(loc_highbits | constantIndex));
}
else if (Ego::Script::PDLTokenKind::Variable == token.get_kind())
else if (Ego::Script::PDLTokenKind::Variable == token.category())
{
auto constantIndex = script._instructions.getConstantPool().getOrCreateConstant(token.getValue());
script._instructions.append(Instruction(loc_highbits | constantIndex));
Expand Down Expand Up @@ -761,7 +761,7 @@ void parser_state_t::raise(bool raiseException, Log::Level level, const Ego::Scr
}
e << ", ";
}
e << "received " << "`" << toString(received.get_kind()) << "`" << Log::EndOfEntry;
e << "received " << "`" << toString(received.category()) << "`" << Log::EndOfEntry;
Log::get() << e;
if (raiseException)
{
Expand Down Expand Up @@ -790,15 +790,15 @@ void parser_state_t::parse_line_by_line( ObjectProfile *ppro, script_info_t& scr
// grab the first opcode

_token = parse_indention(script, state);
if (!_token.is(Ego::Script::PDLTokenKind::Indent))
if (!_token.is_one_of(Ego::Script::PDLTokenKind::Indent))
{
this->raise(true, Log::Level::Error, _token, {Ego::Script::PDLTokenKind::Indent});
}
auto indent = _token.getValue();
_token = parse_token(ppro, script, state);

/* `function` */
if ( _token.is(Ego::Script::PDLTokenKind::Function) )
if ( _token.is_one_of(Ego::Script::PDLTokenKind::Function) )
{
if ( Ego::Script::ScriptFunctions::End == _token.getValue() && 0 == indent )
{
Expand All @@ -815,7 +815,7 @@ void parser_state_t::parse_line_by_line( ObjectProfile *ppro, script_info_t& scr

}
/* `variable assignOperator expression` */
else if ( _token.is(Ego::Script::PDLTokenKind::Variable) )
else if ( _token.is_one_of(Ego::Script::PDLTokenKind::Variable) )
{
int operand_index;
int operands = 0;
Expand All @@ -841,8 +841,8 @@ void parser_state_t::parse_line_by_line( ObjectProfile *ppro, script_info_t& scr

auto isOperand = [](const Ego::Script::PDLToken& token)
{
return token.is(Ego::Script::PDLTokenKind::Variable)
|| token.is(Ego::Script::PDLTokenKind::Constant);
return token.is_one_of(Ego::Script::PDLTokenKind::Variable,
Ego::Script::PDLTokenKind::Constant);
};

if (isOperand(_token))
Expand All @@ -852,7 +852,7 @@ void parser_state_t::parse_line_by_line( ObjectProfile *ppro, script_info_t& scr
_token = parse_token(ppro, script, state);
}
// `unaryPlus|unaryMinus`
else if (_token.get_kind() == Ego::Script::PDLTokenKind::Plus || _token.get_kind() == Ego::Script::PDLTokenKind::Minus)
else if (_token.is_one_of(Ego::Script::PDLTokenKind::Plus, Ego::Script::PDLTokenKind::Minus))
{
// We have some expression of the format `('+'|'-') ...` and transform this into
// `0 ('+'|'-') ...`. This is as close as we can currently get to proper code.
Expand All @@ -869,7 +869,7 @@ void parser_state_t::parse_line_by_line( ObjectProfile *ppro, script_info_t& scr
}

// `((operator - assignOperator) (constant|variable))*`
while ( !_token.is(Ego::Script::PDLTokenKind::EndOfLine) )
while ( !_token.is_one_of(Ego::Script::PDLTokenKind::EndOfLine) )
{
// `operator`
if (!isOperator(_token))
Expand Down Expand Up @@ -908,7 +908,7 @@ void parser_state_t::parse_line_by_line( ObjectProfile *ppro, script_info_t& scr
}

_token.setValue(Ego::Script::ScriptFunctions::End);
_token.set_kind(Ego::Script::PDLTokenKind::Function);
_token.category(Ego::Script::PDLTokenKind::Function);
emit_opcode( _token, 0, script );
_token.setValue(script._instructions.getNumberOfInstructions() + 1);
emit_opcode( _token, 0, script );
Expand Down
2 changes: 1 addition & 1 deletion idlib
Submodule idlib updated 43 files
+2 −1 Makefile
+2 −2 Makefile.Linux
+3 −6 Makefile.Windows
+4 −3 idlib-tests.vcxproj
+18 −9 idlib-tests.vcxproj.filters
+18 −1 idlib.vcxproj
+63 −3 idlib.vcxproj.filters
+16 −0 src/idlib/crtp.hpp
+31 −0 src/idlib/file_system.hpp
+85 −0 src/idlib/file_system/access_mode.hpp
+36 −0 src/idlib/file_system/create_mode.hpp
+63 −0 src/idlib/file_system/error.hpp
+13 −0 src/idlib/file_system/file.hpp
+91 −0 src/idlib/file_system/file_linux.cpp
+65 −0 src/idlib/file_system/file_linux.hpp
+95 −0 src/idlib/file_system/file_windows.cpp
+69 −0 src/idlib/file_system/file_windows.hpp
+18 −0 src/idlib/file_system/internal/footer.hpp
+18 −0 src/idlib/file_system/internal/header.hpp
+13 −0 src/idlib/file_system/mapped_file.hpp
+83 −0 src/idlib/file_system/mapped_file_linux.cpp
+64 −0 src/idlib/file_system/mapped_file_linux.hpp
+115 −0 src/idlib/file_system/mapped_file_windows.cpp
+68 −0 src/idlib/file_system/mapped_file_windows.hpp
+3 −3 src/idlib/idlib.hpp
+60 −0 src/idlib/language/category_element.hpp
+14 −100 src/idlib/language/token.hpp
+1 −1 src/idlib/type/clamped_double_scale.hpp
+5 −5 src/idlib/type/uint64_scale.hpp
+2 −0 src/idlib/utility.hpp
+2 −2 src/idlib/utility/assertion_failed_error.hpp
+13 −13 src/idlib/utility/bitmask_type.hpp
+3 −1 src/idlib/utility/to_string.hpp
+1 −3 tests/idlib/tests/Math.cpp
+3 −3 tests/idlib/tests/color/addition_subtraction.cpp
+3 −3 tests/idlib/tests/color/brightening_darkening.cpp
+2 −2 tests/idlib/tests/color/compose_construction.cpp
+2 −2 tests/idlib/tests/color/copy_construction.cpp
+2 −2 tests/idlib/tests/color/decompose_construction.cpp
+2 −2 tests/idlib/tests/color/interpolation.cpp
+2 −2 tests/idlib/tests/color/inversion.cpp
+61 −0 tests/idlib/tests/file_system/access_mode.cpp
+2 −2 tests/idlib/tests/language/qualified_name.cpp
Loading

0 comments on commit 7e6ddb5

Please sign in to comment.