[opengtl-commits] [405] allow constant in shiva too |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 405
Author: cyrille
Date: 2008-09-20 17:46:14 +0200 (Sat, 20 Sep 2008)
Log Message:
-----------
allow constant in shiva too
Modified Paths:
--------------
trunk/OpenGTL/OpenCTL/OpenCTL/compiler/ParserNG.cpp
trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h
trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/compiler/ParserNG.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/compiler/ParserNG.cpp 2008-09-20 10:48:29 UTC (rev 404)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/compiler/ParserNG.cpp 2008-09-20 15:46:14 UTC (rev 405)
@@ -145,65 +145,8 @@
switch(currentToken().type)
{
case GTLCore::Token::CONST:
- {
- getNextToken();
- const GTLCore::Type* type = parseType();
- if( isOfType( currentToken(), GTLCore::Token::IDENTIFIER ) )
- {
- GTLCore::String name = currentToken().string;
- getNextToken();
- // Decode the size of array (if applicable)
- std::list<int> memberArraySize = expressionsListToIntegersList( parseArraySize(true) );
- if( d->compiler) // This is needed for the Parser's test
- {
- type = d->compiler->typeManager()->getArray( type, memberArraySize.size() );
- }
- // Check that there is an initialiser
- if( isOfType( currentToken(), GTLCore::Token::EQUAL ) )
- {
- getNextToken();
- AST::Expression* expression = 0 ;
- // Check if it's a coumpound expression
- if( currentToken().type == GTLCore::Token::STARTBRACE )
- {
- GTLCore::AST::CoumpoundExpression* coumpoundExpression = parseCoumpoundExpression( type, true );
-/* if( coumpoundExpression->size() != *memberArraySize.begin()) // TODO: recurisvely check other sizes
- {
- GTL_DEBUG( memberArraySize.size() << " " << coumpoundExpression->size() );
- reportError("Wrong coumpound initialiser size", currentToken() );
- }*/
- expression = coumpoundExpression;
- } else {
- expression = parseExpression(true);
- }
- if( isOfType( currentToken(), GTLCore::Token::SEMI ) )
- {
- getNextToken();
- if(expression)
- {
- GTLCore::ScopedName scopedName( nameSpace(), name );
- if( d->tree->containsGlobalConstant( scopedName ) )
- {
- reportError("Constant '" + scopedName.toString() + "' has allready been declared", currentToken());
- } else {
- AST::GlobalConstantDeclaration* gcd = new AST::GlobalConstantDeclaration( scopedName, type , expression );
- variablesManager()->declareConstant( scopedName, gcd->variable() );
- d->tree->append( gcd );
- }
- }
- }
- } else {
- OCTL_DEBUG("Unexpected");
- reportUnexpected( currentToken() );
- reachNextSemi();
- }
- } else {
- OCTL_DEBUG("Unexpected");
- reportUnexpected( currentToken() );
- reachNextSemi();
- }
+ parseConstantDeclaration();
break;
- }
case GTLCore::Token::STRUCT:
parseStructDefinition();
break;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-09-20 10:48:29 UTC (rev 404)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-09-20 15:46:14 UTC (rev 405)
@@ -82,6 +82,67 @@
return d->currentToken;
}
+
+void ParserBase::parseConstantDeclaration()
+{
+ getNextToken();
+ const GTLCore::Type* type = parseType();
+ if( isOfType( currentToken(), GTLCore::Token::IDENTIFIER ) )
+ {
+ GTLCore::String name = currentToken().string;
+ getNextToken();
+ // Decode the size of array (if applicable)
+ std::list<int> memberArraySize = expressionsListToIntegersList( parseArraySize(true) );
+ if( d->compiler) // This is needed for the Parser's test
+ {
+ type = d->compiler->typeManager()->getArray( type, memberArraySize.size() );
+ }
+ // Check that there is an initialiser
+ if( isOfType( currentToken(), GTLCore::Token::EQUAL ) )
+ {
+ getNextToken();
+ AST::Expression* expression = 0 ;
+ // Check if it's a coumpound expression
+ if( currentToken().type == GTLCore::Token::STARTBRACE )
+ {
+ GTLCore::AST::CoumpoundExpression* coumpoundExpression = parseCoumpoundExpression( type, true );
+ /* if( coumpoundExpression->size() != *memberArraySize.begin()) // TODO: recurisvely check other sizes
+ {
+ GTL_DEBUG( memberArraySize.size() << " " << coumpoundExpression->size() );
+ reportError("Wrong coumpound initialiser size", currentToken() );
+ }*/
+ expression = coumpoundExpression;
+ } else {
+ expression = parseExpression(true);
+ }
+ if( isOfType( currentToken(), GTLCore::Token::SEMI ) )
+ {
+ getNextToken();
+ if(expression)
+ {
+ GTLCore::ScopedName scopedName( nameSpace(), name );
+ if( tree()->containsGlobalConstant( scopedName ) )
+ {
+ reportError("Constant '" + scopedName.toString() + "' has allready been declared", currentToken());
+ } else {
+ AST::GlobalConstantDeclaration* gcd = new AST::GlobalConstantDeclaration( scopedName, type , expression );
+ variablesManager()->declareConstant( scopedName, gcd->variable() );
+ tree()->append( gcd );
+ }
+ }
+ }
+ } else {
+ GTL_DEBUG("Unexpected");
+ reportUnexpected( currentToken() );
+ reachNextSemi();
+ }
+ } else {
+ GTL_DEBUG("Unexpected");
+ reportUnexpected( currentToken() );
+ reachNextSemi();
+ }
+}
+
void ParserBase::parseStructDefinition()
{
GTL_ASSERT( d->currentToken.type == Token::STRUCT );
@@ -744,7 +805,7 @@
AST::StatementsList* ParserBase::appendCurrentContextGarbageCollecting( AST::StatementsList* _statementsList )
{
- if( not _statementsList->isReturnStatement() )
+ if( _statementsList and not _statementsList->isReturnStatement() )
{
_statementsList->appendStatement( d->variablesManager.garbageCollectCurrentContext() );
}
@@ -753,7 +814,7 @@
AST::Statement* ParserBase::appendCurrentContextGarbageCollecting( AST::Statement* _statement )
{
- if( not _statement->isReturnStatement() )
+ if( _statement and not _statement->isReturnStatement() )
{
std::list< AST::Statement* > statements;
statements.push_back( _statement );
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h 2008-09-20 10:48:29 UTC (rev 404)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h 2008-09-20 15:46:14 UTC (rev 405)
@@ -108,6 +108,7 @@
virtual const Type* parseType();
const Type* parseFunctionType();
void parseStructDefinition();
+ void parseConstantDeclaration();
/**
* Parse the arguments of a function.
*/
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp 2008-09-20 10:48:29 UTC (rev 404)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp 2008-09-20 15:46:14 UTC (rev 405)
@@ -83,6 +83,9 @@
case GTLCore::Token::END_OF_FILE:
case GTLCore::Token::ENDBRACE:
return;
+ case GTLCore::Token::CONST:
+ parseConstantDeclaration();
+ break;
case GTLCore::Token::STRUCT:
parseStructDefinition();
break;