[opengtl-commits] [425] parse non-constant coumpound expression |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 425
Author: cyrille
Date: 2008-10-06 14:03:38 +0200 (Mon, 06 Oct 2008)
Log Message:
-----------
parse non-constant coumpound expression
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
trunk/OpenGTL/OpenShiva/tests/vectors/coumpoundcreation.shiva
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.h 2008-10-06 11:34:22 UTC (rev 424)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/ConstantCoumpoundExpression.h 2008-10-06 12:03:38 UTC (rev 425)
@@ -17,8 +17,8 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef _AST_COUMPOUND_EXPRESSION_H_
-#define _AST_COUMPOUND_EXPRESSION_H_
+#ifndef _AST_CONSTANT_COUMPOUND_EXPRESSION_H_
+#define _AST_CONSTANT_COUMPOUND_EXPRESSION_H_
#include <vector>
#include "GTLCore/AST/Expression.h"
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-10-06 11:34:22 UTC (rev 424)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-10-06 12:03:38 UTC (rev 425)
@@ -35,6 +35,7 @@
#include "AST/AccessorExpression.h"
#include "AST/BinaryExpression.h"
#include "AST/ConstantCoumpoundExpression.h"
+#include "AST/CoumpoundExpression.h"
#include "AST/Expression.h"
#include "AST/FunctionDeclaration.h"
#include "AST/Tree.h"
@@ -304,8 +305,23 @@
AST::Expression* ParserBase::parseCoumpoundExpression( const Type* _type, bool _constantExpression )
{
GTL_ASSERT( _type );
- GTL_ASSERT( d->currentToken.type == Token::STARTBRACE );
GTL_DEBUG( *_type );
+
+ Token::Type endToken;
+ switch( d->currentToken.type)
+ {
+ case Token::STARTBRACE:
+ endToken = Token::ENDBRACE;
+ break;
+ case Token::STARTBRACKET:
+ endToken = Token::ENDBRACKET;
+ break;
+ default:
+ GTL_DEBUG("unexpected");
+ reportUnexpected( d->currentToken );
+ return 0;
+ }
+
getNextToken(); // Eat '{'
std::vector< AST::Expression* > expressions_;
int index = 0;
@@ -338,10 +354,15 @@
if( d->currentToken.type == Token::COMA )
{
getNextToken();
- } else if( d->currentToken.type == Token::ENDBRACE )
+ } else if( d->currentToken.type == endToken )
{
getNextToken();
- return new AST::ConstantCoumpoundExpression(_type, expressions_);
+ if( _constantExpression )
+ {
+ return new AST::ConstantCoumpoundExpression(_type, expressions_);
+ } else {
+ return new AST::CoumpoundExpression(_type, expressions_);
+ }
}
++index;
}
@@ -407,14 +428,25 @@
const Type* type = parseType();
if( isOfType( d->currentToken, Token::STARTBRACKET ) )
{
- getNextToken();
- AST::Expression* expression = parseExpression(_constantExpression, _type);
- if( expression and isOfType( currentToken(), Token::ENDBRACKET ) )
+ AST::Expression* expression = 0;
+ if( type->dataType() == Type::VECTOR or type->dataType() == Type::ARRAY or type->dataType() == Type::STRUCTURE )
{
+ expression = parseCoumpoundExpression( type, _constantExpression);
+ } else {
getNextToken();
+ expression = parseExpression(_constantExpression, type);
+ isOfType( currentToken(), Token::ENDBRACKET );
+ getNextToken();
+ }
+ if( expression )
+ {
return d->compiler->convertCenter()->createConvertExpression( expression, type );
}
+ } else {
+ GTL_DEBUG("unexpected");
+ reportUnexpected( d->currentToken );
}
+ return 0;
} else {
GTL_DEBUG("unexpected");
reportUnexpected( d->currentToken );
Modified: trunk/OpenGTL/OpenShiva/tests/vectors/coumpoundcreation.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/vectors/coumpoundcreation.shiva 2008-10-06 11:34:22 UTC (rev 424)
+++ trunk/OpenGTL/OpenShiva/tests/vectors/coumpoundcreation.shiva 2008-10-06 12:03:38 UTC (rev 425)
@@ -9,6 +9,9 @@
float2 v = { 1.0,-1.0 };
if( v[0] != 1.0 ) ++count;
if( v[1] != -1.0 ) ++count;
+ float2 v3 = float2( v[0] - 1.0, v[0] + v[1] );
+ if( v3[0] != 0.0 ) ++count;
+ if( v3[1] != 0.0 ) ++count;
return count;
}
}