[opengtl-commits] [347] convert intialiser value to the variable/parameter type |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 347
Author: cyrille
Date: 2008-09-02 00:32:24 +0200 (Tue, 02 Sep 2008)
Log Message:
-----------
convert intialiser value to the variable/parameter type
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/String.cpp
trunk/OpenGTL/OpenGTL/GTLCore/String.h
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-09-01 22:20:16 UTC (rev 346)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-09-01 22:32:24 UTC (rev 347)
@@ -649,11 +649,18 @@
if( d->currentToken.type == Token::EQUAL )
{
getNextToken();
- initialiser = parseExpression( false, ptype );
+ initialiser = d->compiler->convertCenter()->createConvertExpression( parseExpression( false, ptype ), ptype);
+ if( not initialiser )
+ {
+ reportError( "Can't convert initialiser expression to the parameter type, for parameter " + String::number(params.size() + 1) + ".", d->currentToken);
+ deleteAll( params );
+ return;
+ }
needToHaveInitialiser = true;
} else if( needToHaveInitialiser )
{
reportError( "Parameter need to have default initialiser once a parameter on the left had one.", d->currentToken );
+ deleteAll( params );
return;
}
if( d->currentToken.type == Token::COMA or d->currentToken.type == Token::ENDBRACKET )
@@ -685,11 +692,13 @@
} else {
GTL_DEBUG("Unexpected");
reportUnexpected( d->currentToken );
+ deleteAll( params );
return;
}
} else {
GTL_DEBUG("Unexpected");
reportUnexpected( d->currentToken );
+ deleteAll( params );
return;
}
} else {
@@ -947,6 +956,17 @@
// Check if it's a coumpound expression
initialiser = parseExpression( false, type );
initialised = true;
+ if( initialiser )
+ {
+ AST::Expression* previousValue = initialiser;
+ initialiser = d->compiler->convertCenter()->createConvertExpression( initialiser, type );
+ if( not initialiser )
+ {
+ delete previousValue;
+ reportError( "Can't convert value at initialisation to variable type.", d->currentToken );
+ return 0;
+ }
+ }
}
// Create the variable declaration statement
AST::VariableDeclaration* variable = new AST::VariableDeclaration( type, initialiser, constant, initialsize );
Modified: trunk/OpenGTL/OpenGTL/GTLCore/String.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/String.cpp 2008-09-01 22:20:16 UTC (rev 346)
+++ trunk/OpenGTL/OpenGTL/GTLCore/String.cpp 2008-09-01 22:32:24 UTC (rev 347)
@@ -70,6 +70,16 @@
ss >> str;
return str;
}
+
+String String::number(unsigned int i)
+{
+ std::stringstream ss;
+ String str;
+ ss << i;
+ ss >> str;
+ return str;
+}
+
String String::number(float f )
{
std::stringstream ss;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/String.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/String.h 2008-09-01 22:20:16 UTC (rev 346)
+++ trunk/OpenGTL/OpenGTL/GTLCore/String.h 2008-09-01 22:32:24 UTC (rev 347)
@@ -117,6 +117,10 @@
/**
* @return a \ref String containing the number
*/
+ static String number(unsigned int );
+ /**
+ * @return a \ref String containing the number
+ */
static String number(float );
};