Skip to content

Commit

Permalink
prototypical delphi impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens-G committed Jan 23, 2025
1 parent 8f60a37 commit 8cf669f
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 162 deletions.
321 changes: 189 additions & 132 deletions compiler/cpp/src/thrift/generate/t_delphi_generator.cc

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions compiler/cpp/src/thrift/generate/t_netstd_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3476,7 +3476,7 @@ bool t_netstd_generator::is_nullable_type(t_type* ttype) {
}


string t_netstd_generator::nullable_suffix() {
string t_netstd_generator::nullable_suffix() const {
if(target_net_version >= 6) {
return "?";
} else {
Expand Down Expand Up @@ -3518,7 +3518,7 @@ string t_netstd_generator::nullable_field_suffix(t_type* ttype) {
return nullable_suffix();
}

string t_netstd_generator::nullable_value_access(t_type* ttype) {
string t_netstd_generator::nullable_value_access(t_type* ttype) const {
if( target_net_version < 6)
return "";

Expand Down
8 changes: 4 additions & 4 deletions compiler/cpp/src/thrift/generate/t_netstd_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class t_netstd_generator : public t_oop_generator
t_netstd_generator(t_program* program, const map<string, string>& parsed_options, const string& option_string);

bool is_wcf_enabled() const;
bool is_hashcode_enabled() const;
//bool is_hashcode_enabled() const;
bool is_serialize_enabled() const;
bool is_union_enabled() const;

Expand Down Expand Up @@ -170,7 +170,7 @@ class t_netstd_generator : public t_oop_generator
string namespace_dir_;

bool union_;
bool hashcode_;
//bool hashcode_;
bool serialize_;
bool wcf_;
bool use_pascal_case_properties;
Expand Down Expand Up @@ -222,8 +222,8 @@ class t_netstd_generator : public t_oop_generator
bool is_deprecated(std::map<std::string, std::vector<std::string>>& annotations);
bool is_nullable_type(t_type* ttype);
bool force_member_nullable(t_field* tfield); // see there
string nullable_suffix(); // unconditionally
string nullable_suffix() const; // unconditionally
string nullable_field_suffix(t_field* tfield); // depends on field type
string nullable_field_suffix(t_type* ttype); // depends on field type
string nullable_value_access(t_type* ttype); // depends on field type
string nullable_value_access(t_type* ttype) const; // depends on field type
};
8 changes: 4 additions & 4 deletions compiler/cpp/src/thrift/parse/parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

#include "thrift/main.h"

t_type* t_type::get_true_type() {
return const_cast<t_type*>(const_cast<const t_type*>(this)->get_true_type());
t_type* t_type::get_true_type(std::map<std::string, t_type*>* generic) {
return const_cast<t_type*>(const_cast<const t_type*>(this)->get_true_type(generic));
}

const t_type* t_type::get_true_type() const {
const t_type* t_type::get_true_type(std::map<std::string, t_type*>* generic) const {
const t_type* type = this;
while (type->is_typedef()) {
type = ((t_typedef*)type)->get_type();
type = ((t_typedef*)type)->get_type(generic);
}
return type;
}
4 changes: 2 additions & 2 deletions compiler/cpp/src/thrift/parse/t_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class t_field : public t_doc {

~t_field() override = default;

t_type* get_type() { return type_; }
t_type* get_type(std::map<std::string, t_type*>* generic = nullptr) { return type_; }

const t_type* get_type() const { return type_; }
const t_type* get_type(std::map<std::string, t_type*>* generic = nullptr) const { return type_; }

const std::string& get_name() const { return name_; }

Expand Down
20 changes: 16 additions & 4 deletions compiler/cpp/src/thrift/parse/t_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,27 @@ class t_struct : public t_type {

std::map<std::string, t_type*>* map_template_types() {
validate_template_instantiation();

if (tmpl_decl_type_ == nullptr) {
return nullptr;
}
if (tmpl_decl_type_->size() == tmpl_mapped_types_.size()) {
return &tmpl_mapped_types_;
}

hier weiter
if (tmpl_decl_type_->size() != tmpl_mapped_types_.size()) {
int expected_count = 0;
std::vector<std::string>::iterator itKey = tmpl_decl_type_->begin();
std::vector<t_type*>::iterator itVal = get_template_instance_type()->begin();
while ((tmpl_decl_type_->end() != itKey) && (get_template_instance_type()->end() != itVal)) {
tmpl_mapped_types_[*itKey] = *itVal;
if (++expected_count != tmpl_mapped_types_.size()) {
printf("Duplicate type parameter %s at %s\n", itKey->c_str(), name_.c_str());
exit(1);
}
++itKey;
++itVal;
}
}

return &tmpl_mapped_types_;
}

void set_xsd_all(bool xsd_all) { xsd_all_ = xsd_all; }
Expand Down
4 changes: 2 additions & 2 deletions compiler/cpp/src/thrift/parse/t_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class t_type : public t_doc {

const t_program* get_program() const { return program_; }

t_type* get_true_type();
const t_type* get_true_type() const;
t_type* get_true_type(std::map<std::string, t_type*>* generic = nullptr);
const t_type* get_true_type(std::map<std::string, t_type*>* generic = nullptr) const;

// This function will break (maybe badly) unless 0 <= num <= 16.
static char nybble_to_xdigit(int num) {
Expand Down
29 changes: 19 additions & 10 deletions compiler/cpp/src/thrift/parse/t_typedef.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,27 @@
#include "thrift/parse/t_typedef.h"
#include "thrift/parse/t_program.h"

t_type* t_typedef::get_type() {
return const_cast<t_type*>(const_cast<const t_typedef*>(this)->get_type());
t_type* t_typedef::get_type(std::map<std::string, t_type*>* generic) {
return const_cast<t_type*>(const_cast<const t_typedef*>(this)->get_type(generic));
}

const t_type* t_typedef::get_type() const {
if (type_ == nullptr) {
const t_type* type = get_program()->scope()->get_type(symbolic_);
if (type == nullptr) {
printf("Type \"%s\" not defined\n", symbolic_.c_str());
exit(1);
}
const t_type* t_typedef::get_type(std::map<std::string, t_type*>* generic) const {
if (type_ != nullptr) {
return type_;
}

const t_type* type = get_program()->scope()->get_type(symbolic_);
if ((type != nullptr) && (type != this)) {
return type;
}
return type_;

if (generic != nullptr) {
std::map<std::string, t_type*>::const_iterator iter = generic->find(symbolic_);
if ((iter != generic->end()) && (iter->second != this)) {
return iter->second;
}
}

printf("Type \"%s\" not defined\n", symbolic_.c_str());
exit(1);
}
4 changes: 2 additions & 2 deletions compiler/cpp/src/thrift/parse/t_typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class t_typedef : public t_type {

~t_typedef() override = default;

t_type* get_type();
t_type* get_type(std::map<std::string, t_type*>* generic = nullptr);

const t_type* get_type() const;
const t_type* get_type(std::map<std::string, t_type*>* generic = nullptr) const;

const std::string& get_symbolic() const { return symbolic_; }

Expand Down

0 comments on commit 8cf669f

Please sign in to comment.