[opengtl-commits] [705] make compiler works internally with a list of functions

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


Revision: 705
Author:   cyrille
Date:     2009-03-26 19:39:08 +0100 (Thu, 26 Mar 2009)

Log Message:
-----------
make compiler works internally with a list of functions

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/CompilerBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/CompilerBase_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp


Modified: trunk/OpenGTL/OpenGTL/GTLCore/CompilerBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CompilerBase_p.cpp	2009-03-26 14:15:05 UTC (rev 704)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CompilerBase_p.cpp	2009-03-26 18:39:08 UTC (rev 705)
@@ -38,7 +38,7 @@
 struct CompilerBase::Private {
   GTLCore::String moduleName;
   std::list<ErrorMessage> errorMessages;
-  std::map< GTLCore::ScopedName, GTLCore::Function* > functions;
+  std::map< GTLCore::ScopedName, std::list< GTLCore::Function* > > functions;
   std::list<GTLCore::Function*> functionsToDelete;
   ConvertCenter* convertCenter;
   ModuleData* moduleData;
@@ -97,16 +97,16 @@
   return d->moduleName;
 }
 
-GTLCore::Function* CompilerBase::function( const GTLCore::ScopedName&  name)
+const std::list<GTLCore::Function*>* CompilerBase::function( const GTLCore::ScopedName&  name)
 {
   GTL_DEBUG( "Look for function: " << name );
-  std::map< GTLCore::ScopedName, GTLCore::Function* >::iterator it = d->functions.find( name );
+  std::map< GTLCore::ScopedName, std::list< GTLCore::Function* > >::iterator it = d->functions.find( name );
   if( it == d->functions.end() )
   {
     if( name.nameSpace() == "" )
     {
       GTL_DEBUG(" Available functions");
-      for( std::map< GTLCore::ScopedName, GTLCore::Function* >::iterator it2 = d->functions.begin(); it2 != d->functions.end(); ++it2)
+      for( std::map< GTLCore::ScopedName, std::list< GTLCore::Function* > >::iterator it2 = d->functions.begin(); it2 != d->functions.end(); ++it2)
       {
         GTL_DEBUG( it2->first );
       }
@@ -115,20 +115,24 @@
     GTLCore::ScopedName  globalName( "", name.name() );
     return function( globalName );
   } else {
-    return it->second;
+    return &it->second; // TODO check for the best function to call
   }
 }
 
 bool CompilerBase::declareFunction( const GTLCore::ScopedName& name, GTLCore::Function* func)
 {
-  std::map< GTLCore::ScopedName, GTLCore::Function* >::iterator it = d->functions.find( name );
+  std::map< GTLCore::ScopedName, std::list< GTLCore::Function*> >::iterator it = d->functions.find( name );
   if( it == d->functions.end() )
   {
-    d->functions[name] = func;
-    return true;
+    std::list<  GTLCore::Function* > funcs;
+    funcs.push_back(func);
+    d->functions[name] = funcs;
   } else {
-    return false;
+    // TODO check that this overload of the function doesn't already exists
+    it->second.push_back(func);
+//     return false;
   }
+    return true;
 }
 
 ConvertCenter* CompilerBase::convertCenter()

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CompilerBase_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CompilerBase_p.h	2009-03-26 14:15:05 UTC (rev 704)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CompilerBase_p.h	2009-03-26 18:39:08 UTC (rev 705)
@@ -50,7 +50,7 @@
        */
       void appendError( GTLCore::ErrorMessage* );
       const std::list<GTLCore::ErrorMessage>& errorMessages() const;
-      GTLCore::Function* function( const GTLCore::ScopedName&  );
+      const std::list<GTLCore::Function*>* function( const GTLCore::ScopedName&  );
       bool declareFunction( const GTLCore::ScopedName&, GTLCore::Function*);
       /**
        * 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2009-03-26 14:15:05 UTC (rev 704)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2009-03-26 18:39:08 UTC (rev 705)
@@ -1326,13 +1326,15 @@
           GTL_DEBUG( name );
           ScopedName fname( ( name.nameSpace() == "" ) ? d->nameSpace : name.nameSpace(),
                               name.name() );
-          Function* function = d->compiler->function( fname );
-          if( not function )
+          const std::list<Function*>* functionlist = d->compiler->function( fname );
+          if( not functionlist )
           {
             reportError("Unknown function: " + name.toString(), d->currentToken);
             getNextToken();
             return 0;
           }
+          GTL_ASSERT( not functionlist->empty() );
+          Function* function = functionlist->front(); // TODO check for multiple arguments
           getNextToken();
           // Parse arguments
           std::list<AST::Expression*> arguments = parseArguments( function->name().toString(), function->parameters(), 0 );


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