-
Notifications
You must be signed in to change notification settings - Fork 7
Avoid connecting properties for now #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
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 |
|---|---|---|
|
|
@@ -15,31 +15,31 @@ namespace temper { | |
|
|
||
| template<class D> | ||
| int32_t getYear(const std::shared_ptr<D>& d) { | ||
| return d->year; | ||
| return d->_year; | ||
| } | ||
|
Contributor
Author
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 actual fields have uglier names now. And be-cpp currently makes public fields. We shouldn't do that. But even if we keep this organization the same, we could |
||
|
|
||
| template<class D> | ||
| int32_t getMonth(const std::shared_ptr<D>& d) { | ||
| return d->month; | ||
| return d->_month; | ||
| } | ||
|
|
||
| template<class D> | ||
| int32_t getDay(const std::shared_ptr<D>& d) { | ||
| return d->day; | ||
| return d->_day; | ||
| } | ||
|
|
||
| template<class D> | ||
| int32_t getDayOfWeek(const std::shared_ptr<D>& d) { | ||
| static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; | ||
| int64_t y = d->year; | ||
| int64_t m = d->month; | ||
| int64_t y = d->_year; | ||
| int64_t m = d->_month; | ||
| if (m < 1 || m > 12) { | ||
| bubble<int32_t>("month out of range"); | ||
| } | ||
| if (m < 3) { | ||
| y = y - 1; | ||
| } | ||
| int64_t dow = (y + y/4 - y/100 + y/400 + t[m-1] + d->day) % 7; | ||
| int64_t dow = (y + y/4 - y/100 + y/400 + t[m-1] + d->_day) % 7; | ||
| if (dow < 0) { | ||
| dow = dow + 7; | ||
| } | ||
|
|
@@ -50,13 +50,13 @@ namespace temper { | |
| std::string toString( | ||
| const std::shared_ptr<D>& d, | ||
| typename std::enable_if< | ||
| std::is_same<decltype(std::declval<D>().year), int32_t>::value | ||
| && std::is_same<decltype(std::declval<D>().month), int32_t>::value | ||
| && std::is_same<decltype(std::declval<D>().day), int32_t>::value | ||
| std::is_same<decltype(std::declval<D>()._year), int32_t>::value | ||
| && std::is_same<decltype(std::declval<D>()._month), int32_t>::value | ||
| && std::is_same<decltype(std::declval<D>()._day), int32_t>::value | ||
| >::type* = nullptr | ||
| ) { | ||
| std::ostringstream oss; | ||
| int32_t y = d->year; | ||
| int32_t y = d->_year; | ||
| if (y < 0) { | ||
| oss << '-'; y = -y; | ||
| } | ||
|
|
@@ -68,22 +68,22 @@ namespace temper { | |
| oss << "0"; | ||
| } | ||
| oss << y << '-'; | ||
| if (d->month < 10) { | ||
| if (d->_month < 10) { | ||
| oss << '0'; | ||
| } | ||
| oss << d->month << '-'; | ||
| if (d->day < 10) { | ||
| oss << d->_month << '-'; | ||
| if (d->_day < 10) { | ||
| oss << '0'; | ||
| } | ||
| oss << d->day; | ||
| oss << d->_day; | ||
| return oss.str(); | ||
| } | ||
|
|
||
| template<class D> | ||
| int32_t yearsBetween(const std::shared_ptr<D>& from, const std::shared_ptr<D>& to) { | ||
| int32_t years = to->year - from->year; | ||
| if (to->month < from->month | ||
| || (to->month == from->month && to->day < from->day)) { | ||
| int32_t years = to->_year - from->_year; | ||
| if (to->_month < from->_month | ||
| || (to->_month == from->_month && to->_day < from->_day)) { | ||
| years = years - 1; | ||
| } | ||
| return years; | ||
|
|
@@ -92,9 +92,9 @@ namespace temper { | |
| template<class D> | ||
| std::shared_ptr<D> makeDate(int32_t year, int32_t month, int32_t day) { | ||
| std::shared_ptr<D> d = std::make_shared<D>(); | ||
| d->year = year; | ||
| d->month = month; | ||
| d->day = day; | ||
| d->_year = year; | ||
| d->_month = month; | ||
| d->_day = day; | ||
| return d; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -470,7 +470,7 @@ internal object TranslateDotHelper { | |
|
|
||
| internal fun connectedKeyForMember(member: MemberShape): String? = when (member) { | ||
| is MethodShape -> connectedKeyForMethod(member) | ||
| is PropertyShape -> member.connectedKey | ||
| is PropertyShape -> null // connect only through accessors methods for now | ||
|
Contributor
Author
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. Frontend things should go along with this, but that's TODO in this PR. This tmpl restriction at least limits backends from connecting properties themselves until we work more details out in the future. |
||
| is VisibleMemberShape -> member.connectedKey | ||
| else -> null | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,9 +39,9 @@ class DateTodayFn(val sig: Signature2) : CallableValue, Stayless { | |
| val propertyName = propertyShape.name as ModularName | ||
| val propertyParsedName = (propertyName as ResolvedParsedName).baseName | ||
| val value = when (propertyParsedName.nameText) { | ||
| "year" -> Value(today.year, TInt) | ||
| "month" -> Value(today.monthNumber, TInt) | ||
| "day" -> Value(today.dayOfMonth, TInt) | ||
| "_year" -> Value(today.year, TInt) | ||
| "_month" -> Value(today.monthNumber, TInt) | ||
| "_day" -> Value(today.dayOfMonth, TInt) | ||
|
Contributor
Author
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. Interpreter also has to use the private names. |
||
| else -> error(propertyName) | ||
| } | ||
| properties[propertyName] = value | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,22 +90,25 @@ Here's just enough of a Date type to get us started. | |
| * A Date identifies a day in the proleptic Gregorian calendar. | ||
| * It is unconnected to a time of day or a timezone. | ||
| */ | ||
| @imu | ||
| @json | ||
| @connected @imu @json | ||
| @imu @json @connected | ||
| export class Date { | ||
| /** The year. 1900 means 1900. */ | ||
| @connected | ||
| public year: Int; | ||
| public get year(): Int { _year } | ||
| private _year: Int; | ||
|
|
||
| /** The month of the year in [1, 12]. */ | ||
| @connected | ||
| public month: Int; | ||
| public get month(): Int { _month } | ||
| private _month: Int; | ||
|
|
||
| /** | ||
| * The day of the month in [1, 31] | ||
| * additionally constrained by the length of [month]. | ||
| */ | ||
| @connected | ||
| public day: Int; | ||
| public get day(): Int { _day } | ||
| private _day: Int; | ||
|
Contributor
Author
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. Now all getters with private still-imu fields. Key is that the connection is specifically on the getters now. |
||
|
|
||
| @connected | ||
| public constructor(year: Int, month: Int, day: Int): Void throws Bubble { | ||
|
|
@@ -116,9 +119,9 @@ Here's just enough of a Date type to get us started. | |
| } else { | ||
| isLeapYear(year) | ||
| })) { | ||
| this.year = year; | ||
| this.month = month; | ||
| this.day = day; | ||
| this._year = year; | ||
| this._month = month; | ||
| this._day = day; | ||
| } else { | ||
| bubble(); | ||
| } | ||
|
|
||
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.
Clearer intent this way.