[prettyprint] r582 committed - Make const int x = 0; work by differentiating assignability from init-...

0 views
Skip to first unread message

prett...@googlecode.com

unread,
Jul 2, 2010, 2:05:36 PM7/2/10
to pp-d...@googlegroups.com
Revision: 582
Author: thockin
Date: Fri Jul 2 11:05:20 2010
Log: Make const int x = 0; work by differentiating assignability from
init-ability.


http://code.google.com/p/prettyprint/source/detail?r=582

Modified:
/trunk/language/syntax_tree.h
/trunk/language/type.cpp
/trunk/language/type.h

=======================================
--- /trunk/language/syntax_tree.h Wed Jun 30 17:44:21 2010
+++ /trunk/language/syntax_tree.h Fri Jul 2 11:05:20 2010
@@ -665,7 +665,7 @@

// Make sure the type can be initialized correctly.
Expression *expr = init_ident->initializer();
- if (expr && !m_type->is_assignable_from(expr->result_type())) {
+ if (expr && !m_type->is_initializable_from(expr->result_type())) {
throw SyntaxError(parse_position(),
sprintfxx("can't init type '%s' from '%s'",
m_type->to_string(),
=======================================
--- /trunk/language/type.cpp Wed Jun 30 17:44:21 2010
+++ /trunk/language/type.cpp Fri Jul 2 11:05:20 2010
@@ -213,6 +213,12 @@
{
return is_assignable_from(other, DONT_IGNORE_CONST);
}
+
+bool
+Type::is_initializable_from(const Type &other) const
+{
+ return is_assignable_from(other, IGNORE_CONST);
+}

void
Type::sanity_check() const
=======================================
--- /trunk/language/type.h Wed Jun 30 17:44:21 2010
+++ /trunk/language/type.h Fri Jul 2 11:05:20 2010
@@ -108,6 +108,12 @@
bool
is_assignable_from(const Type &other) const;

+ // Type initialization is equivalent to type assignment, except for some
+ // subtle details. Making this a distinct function makes the code easier
+ // to follow.
+ bool
+ is_initializable_from(const Type &other) const;
+
bool
is_comparable_to(const Type &other) const
{

Reply all
Reply to author
Forward
0 new messages