-
Notifications
You must be signed in to change notification settings - Fork 489
Adding the ability to declare properties in interfaces. #287
base: master
Are you sure you want to change the base?
Changes from all commits
02ec580
c9f6049
9291cb1
05dac06
be2f9d9
626d55d
20be293
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@import "properties.djinni" | ||
@import "set.djinni" | ||
@import "derivings.djinni" | ||
@import "nested_collection.djinni" | ||
|
@@ -14,4 +15,4 @@ | |
@import "single_language_interfaces.djinni" | ||
@import "extended_record.djinni" | ||
@import "varnames.djinni" | ||
@import "relative_paths.djinni" | ||
@import "relative_paths.djinni" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: newline at end of file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
properties_test_helper = interface +c { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you include a +o +j test case as well? |
||
|
||
item: i32; | ||
test_string: string; | ||
test_list: list<i32>; | ||
readonly read_only_bool: bool; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test case should include some methods as well as properties, to test that they can be freely mixed. I'd suggest interspersing them in the file too, rather than grouping them together. |
||
static create_new(): properties_test_helper; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: newline at end of file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// AUTOGENERATED FILE - DO NOT MODIFY! | ||
// This file generated by Djinni from properties.djinni | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace testsuite { | ||
|
||
class PropertiesTestHelper { | ||
public: | ||
virtual ~PropertiesTestHelper() {} | ||
|
||
static std::shared_ptr<PropertiesTestHelper> create_new(); | ||
|
||
virtual int32_t get_item() = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getters should be const methods in C++, unless you think there's an issue with that I'm not considering. |
||
virtual void set_item(int32_t new_item) = 0; | ||
|
||
virtual std::string get_test_string() = 0; | ||
virtual void set_test_string(std::string new_test_string) = 0; | ||
|
||
virtual std::vector<int32_t> get_test_list() = 0; | ||
virtual void set_test_list(std::vector<int32_t> new_test_list) = 0; | ||
|
||
virtual bool get_read_only_bool() = 0; | ||
}; | ||
|
||
} // namespace testsuite |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if this shared more code with the method-generating codepaths, since that will help to keep the code simple and make it likely to all be updated in sync with future changes. You should be able to create method definitions from the properties, then use the normal method-generation code.
One option to consider (though it might be too aggressive) would be to implement property generation in most languages as a transformation on the AST, by generating a new AST with methods in place of properties, then running the normal generator on them. That could be a suitable approach for all generators which don't have special support for properties (i.e. ObjC with its @Property declaration).