X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=codegen%2Fmain.cpp;h=0c6090866c4c127c0de8b6db473a0ee58136a2bb;hp=6cf197e748e146de9d85629a0c20998db76d0090;hb=25b3f2c14d2194d6f5aff9a21c09537c4741caa5;hpb=e035276bf0ac5abea21a0aafc6d05e7746e902d1 diff --git a/codegen/main.cpp b/codegen/main.cpp index 6cf197e..0c60908 100644 --- a/codegen/main.cpp +++ b/codegen/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include void print_indentation(unsigned int indentation) { @@ -30,6 +31,20 @@ strip(std::string s, std::string prefix) return std::string(s, prefix.length(), s.length()-prefix.length()); } +std::string +extract_group(const std::string &attrs) +{ + // todo: improve this + std::string error; + std::string to_match("gccxml(libt2n-"); + std::string::size_type p(attrs.find(to_match)); + if (p==std::string::npos) return error; + std::string group(attrs, p+to_match.length(), attrs.length()); + p=group.find_first_of(')'); + assert(p!=std::string::npos); + return std::string(group,0,p); +} + //! get child element by id /*! \return pointer to element having id or null on error @@ -71,7 +86,7 @@ struct type_info std::string name; std::string noref_name; bool operator==(const type_info& o) {return (name==o.name) && (noref_name == o.noref_name);} - std::string noref() const {return noref_name;} + std::string noref() const {return noref_name.empty() ? name : noref_name;} }; std::ostream &operator<<(std::ostream &o, const type_info &t) { @@ -93,8 +108,7 @@ type_info get_type(const xmlpp::Element* root, const std::string &id) // if we recurse - when do we stop? // if it is a typedef? yes? (hmm if the typedef is in the file parsed this will not work) - // TODO: const and reference types (perhaps it is good enough to remove the const and &?) - // non-const reference types/pointers (output error message? not yet supported) + // TODO: const and reference types handling is a ugly hack std::string tag(element->get_name()); if (tag=="ReferenceType") { @@ -115,15 +129,16 @@ type_info get_type(const xmlpp::Element* root, const std::string &id) } assert(element->get_attribute("name")); - assert(element->get_attribute("context")); type_info ret; - ret.name=get_namespace(root, element->get_attribute("context")->get_value())+"::"+element->get_attribute("name")->get_value(); + if (element->get_attribute("context")) + ret.name=get_namespace(root, element->get_attribute("context")->get_value())+"::"; + ret.name+=element->get_attribute("name")->get_value(); return ret; } struct t2n_procedure { - typedef std::map Args; + typedef std::list > Args; std::string group; type_info ret_type; @@ -186,12 +201,11 @@ protected: // check wether the procedure is marked (TODO: improve) // attributes are speparated by spaces? - if (attributes->get_value().find("gccxml(libt2n")==std::string::npos) return; - // TODO: extract command group - // something like: sed 's,gccxml(libt2n-\([a-z]*}),\1,' t2n_procedure f; - f.group=("default"); + f.group=extract_group(attributes->get_value()); + if (f.group.empty()) return; + // todo: handle default group // we need the return type f.ret_type=get_type(root, returns->get_value()); @@ -205,10 +219,10 @@ protected: assert(arg->get_name() == "Argument"); assert(arg->get_attribute("name")); assert(arg->get_attribute("type")); - assert(f.args.find(arg->get_attribute("name")->get_value())==f.args.end()); - f.args[arg->get_attribute("name")->get_value()]=get_type(root, arg->get_attribute("type")->get_value()); + f.args.push_back(std::pair(arg->get_attribute("name")->get_value(), get_type(root, arg->get_attribute("type")->get_value()))); } } + std::cerr << "Found function: " << f << std::endl; m_procedures.push_back(f); }