Skip to content

Commit

Permalink
Organized code in subdirectories.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonask committed May 27, 2012
1 parent 205767c commit 14ae5ea
Show file tree
Hide file tree
Showing 43 changed files with 167 additions and 165 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
SOURCES = $(wildcard base/*.cpp) $(wildcard serialization/*.cpp) $(wildcard type/*.cpp) $(wildcard object/*.cpp) *.cpp

CXXFLAGS = -O0 -g -std=c++11 -stdlib=libc++ -Wall -Werror -Wno-unused

all:
clang++ $(CXXFLAGS) *.cpp -o aspect
clang++.svn $(CXXFLAGS) $(SOURCES) -I. -o aspect
#clang++ $(CXXFLAGS) *.cpp -S
#clang++ -S -emit-llvm $(CXXFLAGS) *.cpp
#clang++ -S -emit-ast $(CXXFLAGS) *.cpp
2 changes: 1 addition & 1 deletion array.hpp → base/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef ARRAY_HPP_6MM1YKSV
#define ARRAY_HPP_6MM1YKSV

#include "basic.hpp"
#include "base/basic.hpp"

#if defined(USE_STD_VECTOR)
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion array_type.cpp → base/array_type.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "array_type.hpp"
#include "base/array_type.hpp"
#include <sstream>

std::string build_variable_length_array_type_name(std::string base_name, const Type* element_type) {
Expand Down
4 changes: 2 additions & 2 deletions array_type.hpp → base/array_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#ifndef ARRAY_TYPE_HPP_JIO2A6YN
#define ARRAY_TYPE_HPP_JIO2A6YN

#include "type.hpp"
#include "archive_node.hpp"
#include "type/type.hpp"
#include "serialization/archive_node.hpp"


struct ArrayType : DerivedType {
Expand Down
2 changes: 1 addition & 1 deletion bag.cpp → base/bag.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "bag.hpp"
#include "base/bag.hpp"

#include <sys/mman.h>

Expand Down
2 changes: 1 addition & 1 deletion bag.hpp → base/bag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef BAG_HPP_LRAVL9CJ
#define BAG_HPP_LRAVL9CJ

#include "array.hpp"
#include "base/array.hpp"

class BagMemoryHandler {
public:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion maybe.hpp → base/maybe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef MAYBE_HPP_8R2MUT0P
#define MAYBE_HPP_8R2MUT0P

#include "basic.hpp"
#include "base/basic.hpp"
#include <type_traits>
#include <new>

Expand Down
2 changes: 1 addition & 1 deletion maybe_type.cpp → base/maybe_type.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "maybe_type.hpp"
#include "base/maybe_type.hpp"

std::string build_maybe_type_name(const Type* inner_type) {
std::stringstream ss;
Expand Down
6 changes: 3 additions & 3 deletions maybe_type.hpp → base/maybe_type.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "type.hpp"
#include "maybe.hpp"
#include "archive_node.hpp"
#include "type/type.hpp"
#include "base/maybe.hpp"
#include "serialization/archive_node.hpp"

std::string build_maybe_type_name(const Type* inner_type);

Expand Down
6 changes: 3 additions & 3 deletions child_list.cpp → object/child_list.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "child_list.hpp"
#include "deserialize_object.hpp"
#include "serialize.hpp"
#include "object/child_list.hpp"
#include "serialization/deserialize_object.hpp"
#include "serialization/serialize.hpp"

void ChildListType::deserialize(ChildList& list, const ArchiveNode& node, IUniverse& universe) const {
if (node.is_array()) {
Expand Down
6 changes: 3 additions & 3 deletions child_list.hpp → object/child_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#ifndef CHILD_LIST_HPP_B25F8VH4
#define CHILD_LIST_HPP_B25F8VH4

#include "array.hpp"
#include "objectptr.hpp"
#include "array_type.hpp"
#include "base/array.hpp"
#include "object/objectptr.hpp"
#include "base/array_type.hpp"

struct ChildList : Array<ObjectPtr<>> {
ChildList() {}
Expand Down
8 changes: 4 additions & 4 deletions composite_type.cpp → object/composite_type.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "composite_type.hpp"
#include "struct_type.hpp"
#include "object/composite_type.hpp"
#include "object/struct_type.hpp"

CompositeType::CompositeType(std::string name, const StructTypeBase* base_type) : base_type_(base_type), name_(std::move(name)), frozen_(false) {
CompositeType::CompositeType(std::string name, const ObjectTypeBase* base_type) : base_type_(base_type), name_(std::move(name)), frozen_(false) {
size_ = this->base_type()->size();
}

Expand All @@ -12,7 +12,7 @@ void CompositeType::add_aspect(const DerivedType* aspect) {
size_ += aspect->size();
}

const StructTypeBase* CompositeType::base_type() const {
const ObjectTypeBase* CompositeType::base_type() const {
return base_type_ ? base_type_ : get_type<Object>();
}

Expand Down
12 changes: 6 additions & 6 deletions composite_type.hpp → object/composite_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#ifndef COMPOSITE_TYPE_HPP_K5R3HGBW
#define COMPOSITE_TYPE_HPP_K5R3HGBW

#include "type.hpp"
#include "archive.hpp"
#include "array.hpp"
#include "type/type.hpp"
#include "serialization/archive.hpp"
#include "base/array.hpp"
#include <new>

struct CompositeType : DerivedType {
CompositeType(std::string name, const StructTypeBase* base_type = nullptr);
CompositeType(std::string name, const ObjectTypeBase* base_type = nullptr);

const StructTypeBase* base_type() const;
const ObjectTypeBase* base_type() const;
void add_aspect(const DerivedType* aspect);
void freeze() { frozen_ = true; }

Expand All @@ -34,7 +34,7 @@ struct CompositeType : DerivedType {
private:
Object* cast(const DerivedType* to, Object* o, const DerivedType* avoid) const;

const StructTypeBase* base_type_;
const ObjectTypeBase* base_type_;
std::string name_;
Array<const DerivedType*> aspects_;
bool frozen_;
Expand Down
6 changes: 3 additions & 3 deletions object.cpp → object/object.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "object.hpp"
#include "reflect.hpp"
#include "universe.hpp"
#include "object/object.hpp"
#include "object/reflect.hpp"
#include "object/universe.hpp"

Object* Object::find_parent() {
Object* object = this;
Expand Down
8 changes: 4 additions & 4 deletions object.hpp → object/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
#ifndef OBJECT_HPP_P40DARL9
#define OBJECT_HPP_P40DARL9

#include "basic.hpp"
#include "base/basic.hpp"

struct IUniverse;
struct Type;
struct DerivedType;
struct StructTypeBase;
template <typename T> struct StructType;
struct ObjectTypeBase;
template <typename T> struct ObjectType;

#define REFLECT \
public: \
static const bool has_reflection__ = true; \
typedef StructTypeBase TypeInfoType; \
typedef ObjectTypeBase TypeInfoType; \
static const TypeInfoType* build_type_info__();

template <typename T> const Type* build_type_info(); // Only used for non-reflected types.
Expand Down
6 changes: 3 additions & 3 deletions objectptr.hpp → object/objectptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#ifndef OBJECTPTR_HPP_WICLN6JL
#define OBJECTPTR_HPP_WICLN6JL

#include "type.hpp"
#include "object.hpp"
#include "reference_type.hpp"
#include "type/type.hpp"
#include "object/object.hpp"
#include "type/reference_type.hpp"

template <typename T = Object, typename Enable = void>
struct ObjectPtr;
Expand Down
26 changes: 13 additions & 13 deletions reflect.hpp → object/reflect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
#ifndef REFLECT_HPP_WJBCX95G
#define REFLECT_HPP_WJBCX95G

#include "object.hpp"
#include "struct_type.hpp"
#include "attribute.hpp"
#include "signal.hpp"
#include "object/object.hpp"
#include "object/struct_type.hpp"
#include "type/attribute.hpp"
#include "object/signal.hpp"
#include <algorithm>

template <typename T>
struct StructTypeBuilder {
typedef StructTypeBuilder<T> Self;
struct ObjectTypeBuilder {
typedef ObjectTypeBuilder<T> Self;

StructTypeBuilder() : super_(nullptr), is_abstract_(false) {}
ObjectTypeBuilder() : super_(nullptr), is_abstract_(false) {}

Self& abstract(bool a = true) { is_abstract_ = true; return *this; }
Self& name(std::string n) { name_ = std::move(n); return *this; }
Self& description(std::string d) { description_ = std::move(d); return *this; }
Self& super(const StructTypeBase* t) { super_ = t; return *this; }
Self& super(const ObjectTypeBase* t) { super_ = t; return *this; }

void check_attribute_name_(const std::string& name) {
const auto reserved_names = {"class", "aspects"};
Expand Down Expand Up @@ -57,16 +57,16 @@ struct StructTypeBuilder {

virtual void define__() = 0;

StructType<T> build__() {
ObjectType<T> build__() {
define__();
StructType<T> type(super_, std::move(name_), std::move(description_));
ObjectType<T> type(super_, std::move(name_), std::move(description_));
type.set_abstract(is_abstract_);
type.set_properties(std::move(attributes_));
type.set_slots(std::move(slots_));
return type;
}

const StructTypeBase* super_;
const ObjectTypeBase* super_;
bool is_abstract_;
std::string name_;
std::string description_;
Expand All @@ -75,8 +75,8 @@ struct StructTypeBuilder {
};

#define BEGIN_TYPE_INFO(TYPE) \
const StructTypeBase* TYPE::build_type_info__() { \
static struct StructTypeBuilderImpl__ : StructTypeBuilder<TYPE> { \
const ObjectTypeBase* TYPE::build_type_info__() { \
static struct ObjectTypeBuilderImpl__ : ObjectTypeBuilder<TYPE> { \
void define__() override { name(#TYPE);

#define END_TYPE_INFO() \
Expand Down
4 changes: 2 additions & 2 deletions signal.cpp → object/signal.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "signal.hpp"
#include "struct_type.hpp"
#include "object/signal.hpp"
#include "object/struct_type.hpp"
#include <sstream>

std::string SignalTypeBase::build_signal_name(const Array<const Type*>& signature) {
Expand Down
10 changes: 5 additions & 5 deletions signal.hpp → object/signal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
#ifndef SIGNAL_HPP_IVWSWZJM
#define SIGNAL_HPP_IVWSWZJM

#include "basic.hpp"
#include "type.hpp"
#include "objectptr.hpp"
#include "archive_node.hpp"
#include "base/basic.hpp"
#include "type/type.hpp"
#include "object/objectptr.hpp"
#include "serialization/archive_node.hpp"

#include <functional>
#include <sstream>
#include <iostream> // TODO: Get rid of.

struct SlotAttributeBase;
struct Object;
struct StructTypeBase;
struct ObjectTypeBase;

struct SignalTypeBase;
template <typename... Args> struct SignalType;
Expand Down
14 changes: 7 additions & 7 deletions struct_type.cpp → object/struct_type.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "struct_type.hpp"
#include "composite_type.hpp"
#include "object/struct_type.hpp"
#include "object/composite_type.hpp"

const StructTypeBase* StructTypeBase::super() const {
const ObjectTypeBase* ObjectTypeBase::super() const {
if (super_ != nullptr) return super_;
const StructTypeBase* object_type = get_type<Object>();
const ObjectTypeBase* object_type = get_type<Object>();
return object_type != this ? object_type : nullptr;
}

Object* StructTypeBase::cast(const DerivedType* to, Object* o) const {
const StructTypeBase* other = dynamic_cast<const StructTypeBase*>(to);
Object* ObjectTypeBase::cast(const DerivedType* to, Object* o) const {
const ObjectTypeBase* other = dynamic_cast<const ObjectTypeBase*>(to);
if (other != nullptr) {
for (const StructTypeBase* t = other; t != nullptr; t = t->super_) {
for (const ObjectTypeBase* t = other; t != nullptr; t = t->super_) {
if (t == this) return o; // TODO: Consider what could be done for multiple inheritance?
}
return nullptr;
Expand Down
24 changes: 12 additions & 12 deletions struct_type.hpp → object/struct_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
#ifndef STRUCT_TYPE_HPP_PTB31EJN
#define STRUCT_TYPE_HPP_PTB31EJN

#include "type.hpp"
#include "type/type.hpp"
#include <memory>

#include <new>
#include "attribute.hpp"
#include "signal.hpp"
#include "type/attribute.hpp"
#include "object/signal.hpp"

struct SlotAttributeBase;
template <typename T> struct SlotForObject;

struct StructTypeBase : DerivedType {
struct ObjectTypeBase : DerivedType {
const std::string& name() const override { return name_; }
const std::string& description() const { return description_; }
Object* cast(const DerivedType* to, Object* o) const override;
const StructTypeBase* super() const;
const ObjectTypeBase* super() const;
virtual Array<const AttributeBase*> attributes() const = 0;
virtual size_t num_slots() const = 0;
virtual const SlotAttributeBase* slot_at(size_t idx) const = 0;
Expand All @@ -36,16 +36,16 @@ struct StructTypeBase : DerivedType {
return nullptr;
}
protected:
StructTypeBase(const StructTypeBase* super, std::string name, std::string description) : super_(super), name_(std::move(name)), description_(std::move(description)) {}
ObjectTypeBase(const ObjectTypeBase* super, std::string name, std::string description) : super_(super), name_(std::move(name)), description_(std::move(description)) {}

const StructTypeBase* super_;
const ObjectTypeBase* super_;
std::string name_;
std::string description_;
};

template <typename T>
struct StructType : TypeFor<T, StructTypeBase> {
StructType(const StructTypeBase* super, std::string name, std::string description) : TypeFor<T, StructTypeBase>(super, std::move(name), std::move(description)), is_abstract_(false) {}
struct ObjectType : TypeFor<T, ObjectTypeBase> {
ObjectType(const ObjectTypeBase* super, std::string name, std::string description) : TypeFor<T, ObjectTypeBase>(super, std::move(name), std::move(description)), is_abstract_(false) {}

void construct(byte* place, IUniverse& universe) const {
Object* p = ::new(place) T;
Expand Down Expand Up @@ -95,7 +95,7 @@ struct StructType : TypeFor<T, StructTypeBase> {


template <typename T>
void StructType<T>::deserialize(T& object, const ArchiveNode& node, IUniverse& universe) const {
void ObjectType<T>::deserialize(T& object, const ArchiveNode& node, IUniverse& universe) const {
auto s = this->super();
if (s) s->deserialize(reinterpret_cast<byte*>(&object), node, universe);

Expand All @@ -105,7 +105,7 @@ void StructType<T>::deserialize(T& object, const ArchiveNode& node, IUniverse& u
}

template <typename T>
void StructType<T>::serialize(const T& object, ArchiveNode& node, IUniverse& universe) const {
void ObjectType<T>::serialize(const T& object, ArchiveNode& node, IUniverse& universe) const {
auto s = this->super();
if (s) s->serialize(reinterpret_cast<const byte*>(&object), node, universe);

Expand All @@ -117,7 +117,7 @@ void StructType<T>::serialize(const T& object, ArchiveNode& node, IUniverse& uni

template <typename T, typename R, typename... Args>
const SlotAttributeBase* MemberSlotInvoker<T,R,Args...>::slot() const {
const StructTypeBase* type = get_type<T>();
const ObjectTypeBase* type = get_type<T>();
return type->find_slot_for_method(member_);
}

Expand Down
4 changes: 2 additions & 2 deletions universe.cpp → object/universe.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "universe.hpp"
#include "struct_type.hpp"
#include "object/universe.hpp"
#include "object/struct_type.hpp"

#include <iomanip>

Expand Down
Loading

0 comments on commit 14ae5ea

Please sign in to comment.