Permalink
Browse files

Semantic analysis of postfix increment/decrement expressions OK for

fundamental types
  • Loading branch information...
1 parent 1f6f36c commit 2eed3b7736002dcb0329f78c5d02ad9d500ce6da Florian Goujeon committed Aug 18, 2011
@@ -505,6 +505,8 @@ struct expression_to_string<EXPRESSION> \
EXPRESSION_TO_STRING(prefix_increment_expression, "prefix increment")
EXPRESSION_TO_STRING(prefix_decrement_expression, "prefix decrement")
+ EXPRESSION_TO_STRING(postfix_increment_expression, "postfix increment")
+ EXPRESSION_TO_STRING(postfix_decrement_expression, "postfix decrement")
EXPRESSION_TO_STRING(indirection_expression, "indirection")
EXPRESSION_TO_STRING(pointer_expression, "pointer")
EXPRESSION_TO_STRING(negation_expression, "negation")
@@ -201,6 +201,32 @@ create_expression_from_postfix_expression
DeclarativeRegion& declarative_region
);
+template<class DeclarativeRegion>
+semantic_entities::expression_t
+create_expression_from_postfix_expression_first_part
+(
+ const syntax_nodes::postfix_expression_first_part& postfix_expression_first_part_node,
+ DeclarativeRegion& declarative_region
+);
+
+template<class DeclarativeRegion>
+semantic_entities::expression_t
+create_expression_from_postfix_expression_last_part_seq
+(
+ const syntax_nodes::postfix_expression_last_part_seq& postfix_expression_last_part_seq_node,
+ semantic_entities::expression_t expr,
+ DeclarativeRegion& declarative_region
+);
+
+template<class DeclarativeRegion>
+semantic_entities::expression_t
+create_expression_from_postfix_expression_last_part
+(
+ const syntax_nodes::postfix_expression_last_part& postfix_expression_last_part_node,
+ const semantic_entities::expression_t& expr,
+ DeclarativeRegion& declarative_region
+);
+
template<class DeclarativeRegion>
semantic_entities::expression_t
create_expression_from_primary_expression
@@ -704,8 +704,34 @@ create_expression_from_postfix_expression
using namespace semantic_entities;
const postfix_expression_first_part& first_part_node = get_first_part(postfix_expression_node);
+ semantic_entities::expression_t expr = create_expression_from_postfix_expression_first_part(first_part_node, declarative_region);
- if(const boost::optional<const primary_expression&>& opt_primary_expression_node = get<primary_expression>(&first_part_node))
+ const optional_node<postfix_expression_last_part_seq>& opt_postfix_expression_last_part_seq_node = get_last_part_seq(postfix_expression_node);
+ if(opt_postfix_expression_last_part_seq_node)
+ return
+ create_expression_from_postfix_expression_last_part_seq
+ (
+ *opt_postfix_expression_last_part_seq_node,
+ expr,
+ declarative_region
+ )
+ ;
+ else
+ return expr;
+}
+
+template<class DeclarativeRegion>
+semantic_entities::expression_t
+create_expression_from_postfix_expression_first_part
+(
+ const syntax_nodes::postfix_expression_first_part& postfix_expression_first_part_node,
+ DeclarativeRegion& declarative_region
+)
+{
+ using namespace syntax_nodes;
+ using namespace semantic_entities;
+
+ if(const boost::optional<const primary_expression&>& opt_primary_expression_node = get<primary_expression>(&postfix_expression_first_part_node))
{
return create_expression_from_primary_expression(*opt_primary_expression_node, declarative_region);
}
@@ -715,6 +741,56 @@ create_expression_from_postfix_expression
}
}
+template<class DeclarativeRegion>
+semantic_entities::expression_t
+create_expression_from_postfix_expression_last_part_seq
+(
+ const syntax_nodes::postfix_expression_last_part_seq& postfix_expression_last_part_seq_node,
+ semantic_entities::expression_t expr,
+ DeclarativeRegion& declarative_region
+)
+{
+ for(const syntax_nodes::postfix_expression_last_part& node: postfix_expression_last_part_seq_node)
+ expr = create_expression_from_postfix_expression_last_part(node, expr, declarative_region);
+
+ return expr;
+}
+
+template<class DeclarativeRegion>
+semantic_entities::expression_t
+create_expression_from_postfix_expression_last_part
+(
+ const syntax_nodes::postfix_expression_last_part& postfix_expression_last_part_node,
+ const semantic_entities::expression_t& expr,
+ DeclarativeRegion& /*declarative_region*/
+)
+{
+ using namespace syntax_nodes;
+ using namespace semantic_entities;
+
+ //square_bracketed_expression,
+ //round_bracketed_optional_expression,
+ //dot_id_expression,
+ //arrow_id_expression,
+ //dot_pseudo_destructor_name,
+ //arrow_pseudo_destructor_name,
+ //predefined_text_node<str::double_plus>,
+ //predefined_text_node<str::double_minus>
+
+ if(get<predefined_text_node<str::double_plus>>(&postfix_expression_last_part_node))
+ return semantic_entities::postfix_increment_expression
+ (
+ expr
+ );
+ else if(get<predefined_text_node<str::double_minus>>(&postfix_expression_last_part_node))
+ return semantic_entities::postfix_decrement_expression
+ (
+ expr
+ );
+ else
+ assert(false); //TODO
+}
+
template<class DeclarativeRegion>
semantic_entities::expression_t
create_expression_from_primary_expression
@@ -73,6 +73,8 @@ operator()(const TYPE&) \
RETURN_SINGLE_OPERAND_TYPE(prefix_increment_expression)
RETURN_SINGLE_OPERAND_TYPE(prefix_decrement_expression)
+ RETURN_SINGLE_OPERAND_TYPE(postfix_increment_expression)
+ RETURN_SINGLE_OPERAND_TYPE(postfix_decrement_expression)
type_t
operator()(const indirection_expression& expr)
@@ -38,6 +38,8 @@ typedef
//unary expressions
prefix_increment_expression,
prefix_decrement_expression,
+ postfix_increment_expression,
+ postfix_decrement_expression,
indirection_expression,
pointer_expression,
negation_expression,
@@ -132,25 +134,29 @@ struct expression_t: public expression_t_t
expression_t
(
const U& value,
- typename boost::disable_if<boost::is_same<U, variant>>::type* = 0
+ typename boost::disable_if<boost::is_const<U>>::type* = 0,
+ typename boost::disable_if<boost::is_reference<U>>::type* = 0,
+ typename boost::disable_if<boost::is_same<U, expression_t>>::type* = 0
):
expression_t_t(value)
{
}
- //if U is a reference of non-const
+ //for noncopyable movable types
template<typename U>
expression_t
(
- U& value,
- typename boost::disable_if<boost::is_same<U, variant>>::type* = 0
+ U&& value,
+ typename boost::disable_if<boost::is_const<U>>::type* = 0,
+ typename boost::disable_if<boost::is_reference<U>>::type* = 0,
+ typename boost::disable_if<boost::is_same<U, expression_t>>::type* = 0
):
expression_t_t(value)
{
}
- expression_t(const expression_t_t& rhs):
- expression_t_t(rhs)
+ expression_t(const expression_t& rhs):
+ expression_t_t(static_cast<const expression_t_t&>(rhs))
{
}
};
@@ -31,6 +31,8 @@ enum class expression_tag
{
PREFIX_INCREMENT_EXPRESSION,
PREFIX_DECREMENT_EXPRESSION,
+ POSTFIX_INCREMENT_EXPRESSION,
+ POSTFIX_DECREMENT_EXPRESSION,
INDIRECTION_EXPRESSION,
POINTER_EXPRESSION,
NEGATION_EXPRESSION,
@@ -79,6 +81,16 @@ typedef
prefix_decrement_expression
;
+typedef
+ unary_expression<static_cast<int>(expression_tag::POSTFIX_INCREMENT_EXPRESSION)>
+ postfix_increment_expression
+;
+
+typedef
+ unary_expression<static_cast<int>(expression_tag::POSTFIX_DECREMENT_EXPRESSION)>
+ postfix_decrement_expression
+;
+
typedef
unary_expression<static_cast<int>(expression_tag::INDIRECTION_EXPRESSION)>
indirection_expression
@@ -104,6 +104,13 @@ get_first_part(const postfix_expression& o)
return get<0>(o);
}
+inline
+const optional_node<postfix_expression_last_part_seq>&
+get_last_part_seq(const postfix_expression& o)
+{
+ return get<1>(o);
+}
+
}}} //namespace scalpel::cpp::syntax_nodes
#include "detail/macros/sequence_node_pimpl_declaration_undef.hpp"

0 comments on commit 2eed3b7

Please sign in to comment.