-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
147 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
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,36 @@ | ||
#include "test_generator_domain.hpp" | ||
|
||
register_classes(Animal, Cat, Dog, Property, DomesticCat, DomesticDog); | ||
|
||
define_method(void, kick, (Dog&, std::ostream& os)) { | ||
os << "bark"; | ||
} | ||
|
||
define_method(void, kick, (Cat&, std::ostream& os)) { | ||
os << "hiss"; | ||
} | ||
|
||
// create an ambiguity with the following two definitions | ||
define_method(void, meet, (Cat&, Animal&, std::ostream& os)) { | ||
os << "ignore"; | ||
} | ||
|
||
define_method(void, meet, (Animal&, Dog&, std::ostream& os)) { | ||
os << "wag tail"; | ||
} | ||
// ^^^ ambiguous | ||
|
||
define_method(void, meet, (Dog&, Cat&, std::ostream& os)) { | ||
os << "chase"; | ||
} | ||
|
||
|
||
define_method(void, identify, (DomesticCat & animal, std::ostream& os)) { | ||
os << animal.owner << "'s" | ||
<< " cat"; | ||
} | ||
|
||
define_method(void, identify, (DomesticDog & animal, std::ostream& os)) { | ||
os << animal.owner << "'s" | ||
<< " dog"; | ||
} |
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,52 @@ | ||
#ifndef TEST_GENERATOR_DOMAIN_HPP | ||
#define TEST_GENERATOR_DOMAIN_HPP | ||
|
||
#include <string> | ||
|
||
#include <yorel/yomm2/policy.hpp> | ||
|
||
struct throw_policy | ||
: yorel::yomm2::default_policy::rebind<throw_policy>::replace< | ||
yorel::yomm2::policy::error_handler, | ||
yorel::yomm2::policy::throw_error> {}; | ||
|
||
#define YOMM2_DEFAULT_POLICY throw_policy | ||
|
||
#include <yorel/yomm2/keywords.hpp> | ||
|
||
#if __has_include("test_generator_slots.hpp") | ||
#include "test_generator_slots.hpp" | ||
#endif | ||
|
||
struct Animal { | ||
virtual ~Animal() { | ||
} | ||
}; | ||
|
||
struct Cat : Animal {}; | ||
struct Dog : Animal {}; | ||
|
||
struct Property { | ||
explicit Property(std::string owner) : owner(owner) { | ||
} | ||
|
||
virtual ~Property() { | ||
} | ||
|
||
std::string owner; | ||
}; | ||
|
||
struct DomesticCat : Cat, Property { | ||
using Property::Property; | ||
}; | ||
|
||
struct DomesticDog : Dog, Property { | ||
using Property::Property; | ||
}; | ||
|
||
declare_method(void, kick, (virtual_<Animal&>, std::ostream&)); | ||
declare_method( | ||
void, meet, (virtual_<Animal&>, virtual_<Animal&>, std::ostream&)); | ||
declare_method(void, identify, (virtual_<Property&>, std::ostream&)); | ||
|
||
#endif // TEST_GENERATOR_DOMAIN_HPP |
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,27 @@ | ||
// Copyright (c) 2018-2024 Jean-Louis Leroy | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// See accompanying file LICENSE_1_0.txt | ||
// or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
|
||
#include "test_generator_domain.hpp" | ||
|
||
#include <iostream> | ||
#include <yorel/yomm2/generator.hpp> | ||
|
||
int main(int argc, char* argv[]) { | ||
using namespace yorel::yomm2; | ||
|
||
auto compiler = update<throw_policy>(); | ||
generator generator; | ||
|
||
std::ofstream slots("test_generator_slots.hpp"); | ||
generator.add_forward_declarations() | ||
.write_forward_declarations(slots) | ||
.write_static_offsets(slots); | ||
|
||
std::ofstream tables("test_generator_tables.hpp"); | ||
generator.encode_dispatch_data(compiler, tables); | ||
|
||
return 0; | ||
} |