[opengtl-commits] [406] convert arguments give to a function to the type

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 406
Author:   cyrille
Date:     2008-09-21 02:12:53 +0200 (Sun, 21 Sep 2008)

Log Message:
-----------
convert arguments give to a function to the type

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Function_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp


Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-09-20 15:46:14 UTC (rev 405)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-09-21 00:12:53 UTC (rev 406)
@@ -608,11 +608,12 @@
       llvm::Value* value = 0;
       if( (*it)->type()->dataType() == GTLCore::Type::ARRAY or (*it)->type()->dataType() == GTLCore::Type::STRUCTURE )
       {
-        if( AST::AccessorExpression* aexp = dynamic_cast<AST::AccessorExpression*>( *it ) )
+        AST::AccessorExpression* aexp = dynamic_cast<AST::AccessorExpression*>( *it );
+        if( aexp and not dynamic_cast<AST::FunctionMemberAccessorExpression*>( aexp ) )
         {
           value = aexp->pointer( _gc, bb );
         } else if( dynamic_cast<AST::FunctionCallExpression*>( *it )
-                   or dynamic_cast<AST::GlobalDataExpression*>( *it ) ) {
+                   or dynamic_cast<AST::GlobalDataExpression*>( *it ) or dynamic_cast<AST::FunctionMemberAccessorExpression*>( aexp ) ) {
             value = (*it)->generateValue(_gc, bb).value();
         } else {
           GTL_ABORT("Can't pass an array or a structure");

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Function_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Function_p.cpp	2008-09-20 15:46:14 UTC (rev 405)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Function_p.cpp	2008-09-21 00:12:53 UTC (rev 406)
@@ -95,7 +95,7 @@
   std::vector<const llvm::Type*> llvmArguments;
   for(unsigned int i = 0; i < arguments.size(); ++i)
   {
-    llvmArguments.push_back( arguments[i].type()->d->type());
+    llvmArguments.push_back( arguments[i].type()->d->asArgumentType() );
   }
   std::vector<llvm::Function*> functions(arguments.size() + 1);
   functions[arguments.size() ] = dynamic_cast<llvm::Function*>( _module->getOrInsertFunction( _symbolName, llvm::FunctionType::get(retType->d->type(), llvmArguments, false ) ) );

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-09-20 15:46:14 UTC (rev 405)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-09-21 00:12:53 UTC (rev 406)
@@ -223,7 +223,7 @@
         {
           reportError("Unknown member: '" + name + "' for structure " + _expression->type()->structName(), d->currentToken );
         } else {
-          std::list<AST::Expression*> arguments = parseArguments( sfm->name(), sfm->parameters() );
+          std::list<AST::Expression*> arguments = parseArguments( sfm->name(), sfm->parameters(), 1 );
           return new AST::FunctionMemberAccessorExpression(_expression, sfm, arguments);
         }
       } else {
@@ -1207,7 +1207,7 @@
           }
           getNextToken();
           // Parse arguments
-          std::list<AST::Expression*> arguments = parseArguments( function->name().toString(), function->parameters() );
+          std::list<AST::Expression*> arguments = parseArguments( function->name().toString(), function->parameters(), 0 );
           if( arguments.size() >= function->d->data->minimumParameters() and arguments.size() <= function->d->data->maximumParameters() )
           {
             return new AST::FunctionCallExpression( function, arguments ) ;
@@ -1240,7 +1240,7 @@
   return 0;
 }
 
-std::list<AST::Expression*> ParserBase::parseArguments( const String& _name, const std::vector< Parameter >& _parameters )
+std::list<AST::Expression*> ParserBase::parseArguments( const String& _name, const std::vector< Parameter >& _parameters, int firstParameter )
 {
   std::list<AST::Expression*> arguments;
   while(true)
@@ -1248,15 +1248,27 @@
     if( d->currentToken.type == Token::ENDBRACKET )
     {
       break;
-    } else if( arguments.size() == _parameters.size() ) {
+    } else if( arguments.size() + firstParameter == _parameters.size() ) {
       // Too much arguments
       reportError( "Too many arguments for function '" + _name + "'", d->currentToken);
       return arguments;
     } else {
       int posArg = arguments.size();
-      AST::Expression* expression = parseExpression( false, _parameters[ posArg ].type() );
+      AST::Expression* expression = parseExpression( false, _parameters[ posArg + firstParameter].type() );
+      if(not expression)
+      {
+        return arguments;
+      }
+      GTL_DEBUG( *_parameters[ posArg + firstParameter ].type() << " " << *expression->type() );
+      expression = d->compiler->convertCenter()->createConvertExpression( expression, _parameters[ posArg  + firstParameter ].type() );
+      if( not expression )
+      {
+        GTL_ABORT("");
+        reportError("Can't convert parameter " + String::number( posArg + 1 ), d->currentToken  );
+        return arguments;
+      }
       arguments.push_back( expression);
-      if( _parameters[ posArg ].output() )
+      if( _parameters[ posArg + firstParameter ].output() )
       {
         if( not dynamic_cast< AST::AccessorExpression* >( expression ) )
         {

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h	2008-09-20 15:46:14 UTC (rev 405)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.h	2008-09-21 00:12:53 UTC (rev 406)
@@ -112,7 +112,7 @@
       /**
        * Parse the arguments of a function.
        */
-      std::list<AST::Expression*> parseArguments( const String& _name, const std::vector< Parameter >& _parameters );
+      std::list<AST::Expression*> parseArguments( const String& _name, const std::vector< Parameter >& _parameters, int firstParameter );
       /**
        * Parse statement of the style "[ 10 ]" or "[ 2 + 3 ]", it's use for variables
        * or constants definition.

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-09-20 15:46:14 UTC (rev 405)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-09-21 00:12:53 UTC (rev 406)
@@ -170,11 +170,11 @@
   type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
           GTLCore::Function::Private::createExternalFunction(
                 _module, "intersect", "region_wrap_intersect", GTLCore::Type::Void, 2,
-                GTLCore::Type::Pointer, GTLCore::Type::Pointer ) ) );
+                GTLCore::Type::Pointer, type ) ) );
   type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
           GTLCore::Function::Private::createExternalFunction(
                 _module, "union", "region_wrap_union", GTLCore::Type::Void, 2,
-                GTLCore::Type::Pointer, GTLCore::Type::Pointer ) ) );
+                GTLCore::Type::Pointer, type ) ) );
   type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
           GTLCore::Function::Private::createExternalFunction(
                 _module, "outset", "region_wrap_outset", GTLCore::Type::Void, 2,


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/