Private table_
parent
b0fa5ce684
commit
6e691b06ff
|
@ -26,7 +26,7 @@ void ReturnType::wrap_result(const string& out, const string& result,
|
||||||
if (category == CLASS) {
|
if (category == CLASS) {
|
||||||
string objCopy, ptrType;
|
string objCopy, ptrType;
|
||||||
ptrType = "Shared" + name;
|
ptrType = "Shared" + name;
|
||||||
const bool isVirtual = typeAttributes.at(cppType).isVirtual;
|
const bool isVirtual = typeAttributes.attributes(cppType).isVirtual;
|
||||||
if (isVirtual) {
|
if (isVirtual) {
|
||||||
if (isPtr)
|
if (isPtr)
|
||||||
objCopy = result;
|
objCopy = result;
|
||||||
|
|
|
@ -21,42 +21,61 @@
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/range/adaptor/map.hpp>
|
||||||
|
#include <boost/range/algorithm/copy.hpp>
|
||||||
|
|
||||||
|
#include <iterator> // std::ostream_iterator
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace wrap {
|
namespace wrap {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void TypeAttributesTable::addClasses(const vector<Class>& classes) {
|
const TypeAttributes& TypeAttributesTable::attributes(const string& key) const {
|
||||||
BOOST_FOREACH(const Class& cls, classes) {
|
try {
|
||||||
if(!insert(make_pair(cls.qualifiedName("::"), TypeAttributes(cls.isVirtual))).second)
|
return table_.at(key);
|
||||||
throw DuplicateDefinition("class " + cls.qualifiedName("::"));
|
} catch (const out_of_range& oor) {
|
||||||
}
|
cerr << "Class::method: key not found: " << oor.what()
|
||||||
|
<< ", methods are:\n";
|
||||||
|
using boost::adaptors::map_keys;
|
||||||
|
ostream_iterator<string> out_it(cerr, "\n");
|
||||||
|
boost::copy(table_ | map_keys, out_it);
|
||||||
|
throw runtime_error("Internal error in wrap");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void TypeAttributesTable::addForwardDeclarations(const vector<ForwardDeclaration>& forwardDecls) {
|
void TypeAttributesTable::addClasses(const vector<Class>& classes) {
|
||||||
BOOST_FOREACH(const ForwardDeclaration& fwDec, forwardDecls) {
|
BOOST_FOREACH(const Class& cls, classes) {
|
||||||
if(!insert(make_pair(fwDec.name, TypeAttributes(fwDec.isVirtual))).second)
|
if (!table_.insert(
|
||||||
throw DuplicateDefinition("class " + fwDec.name);
|
make_pair(cls.qualifiedName("::"), TypeAttributes(cls.isVirtual))).second)
|
||||||
}
|
throw DuplicateDefinition("class " + cls.qualifiedName("::"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void TypeAttributesTable::checkValidity(const vector<Class>& classes) const {
|
void TypeAttributesTable::addForwardDeclarations(
|
||||||
BOOST_FOREACH(const Class& cls, classes) {
|
const vector<ForwardDeclaration>& forwardDecls) {
|
||||||
// Check that class is virtual if it has a parent
|
BOOST_FOREACH(const ForwardDeclaration& fwDec, forwardDecls) {
|
||||||
if (!cls.qualifiedParent.empty() && !cls.isVirtual)
|
if (!table_.insert(make_pair(fwDec.name, TypeAttributes(fwDec.isVirtual))).second)
|
||||||
throw AttributeError(cls.qualifiedName("::"),
|
throw DuplicateDefinition("class " + fwDec.name);
|
||||||
"Has a base class so needs to be declared virtual, change to 'virtual class "
|
|
||||||
+ cls.name + " ...'");
|
|
||||||
// Check that parent is virtual as well
|
|
||||||
Qualified parent = cls.qualifiedParent;
|
|
||||||
if (!parent.empty() && !at(parent.qualifiedName("::")).isVirtual)
|
|
||||||
throw AttributeError(parent.qualifiedName("::"),
|
|
||||||
"Is the base class of " + cls.qualifiedName("::")
|
|
||||||
+ ", so needs to be declared virtual");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
void TypeAttributesTable::checkValidity(const vector<Class>& classes) const {
|
||||||
|
BOOST_FOREACH(const Class& cls, classes) {
|
||||||
|
// Check that class is virtual if it has a parent
|
||||||
|
if (!cls.qualifiedParent.empty() && !cls.isVirtual)
|
||||||
|
throw AttributeError(cls.qualifiedName("::"),
|
||||||
|
"Has a base class so needs to be declared virtual, change to 'virtual class "
|
||||||
|
+ cls.name + " ...'");
|
||||||
|
// Check that parent is virtual as well
|
||||||
|
Qualified parent = cls.qualifiedParent;
|
||||||
|
if (!parent.empty() && !table_.at(parent.qualifiedName("::")).isVirtual)
|
||||||
|
throw AttributeError(parent.qualifiedName("::"),
|
||||||
|
"Is the base class of " + cls.qualifiedName("::")
|
||||||
|
+ ", so needs to be declared virtual");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
|
|
||||||
namespace wrap {
|
namespace wrap {
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
class Class;
|
class Class;
|
||||||
|
|
||||||
/** Attributes about valid classes, both for classes defined in this module and
|
/** Attributes about valid classes, both for classes defined in this module and
|
||||||
* also those forward-declared from others. At the moment this only contains
|
* also those forward-declared from others. At the moment this only contains
|
||||||
* whether the class is virtual, which is used to know how to copy the class,
|
* whether the class is virtual, which is used to know how to copy the class,
|
||||||
|
@ -37,18 +37,33 @@ namespace wrap {
|
||||||
*/
|
*/
|
||||||
struct TypeAttributes {
|
struct TypeAttributes {
|
||||||
bool isVirtual;
|
bool isVirtual;
|
||||||
TypeAttributes() : isVirtual(false) {}
|
TypeAttributes() :
|
||||||
TypeAttributes(bool isVirtual) : isVirtual(isVirtual) {}
|
isVirtual(false) {
|
||||||
|
}
|
||||||
|
TypeAttributes(bool isVirtual) :
|
||||||
|
isVirtual(isVirtual) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Map of type names to attributes. */
|
/** Map of type names to attributes. */
|
||||||
class TypeAttributesTable : public std::map<std::string, TypeAttributes> {
|
class TypeAttributesTable {
|
||||||
|
|
||||||
|
std::map<std::string, TypeAttributes> table_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TypeAttributesTable() {}
|
|
||||||
|
/// Constructor
|
||||||
|
TypeAttributesTable() {
|
||||||
|
}
|
||||||
|
|
||||||
void addClasses(const std::vector<Class>& classes);
|
void addClasses(const std::vector<Class>& classes);
|
||||||
void addForwardDeclarations(const std::vector<ForwardDeclaration>& forwardDecls);
|
void addForwardDeclarations(
|
||||||
|
const std::vector<ForwardDeclaration>& forwardDecls);
|
||||||
|
|
||||||
|
/// Access attributes associated with key, informative failure
|
||||||
|
const TypeAttributes& attributes(const std::string& key) const;
|
||||||
|
|
||||||
|
/// Check that all virtual classes are properly defined
|
||||||
void checkValidity(const std::vector<Class>& classes) const;
|
void checkValidity(const std::vector<Class>& classes) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue