Commits

Anonymous committed 3bbef37

make it possible to not have a declaration registry

Comments (0)

Files changed (4)

Cauchy/AST/Expression.cpp

 
 const Cauchy::Type* Cauchy::AST::FunctionCallExpression::type() const
 {
-  CAUCHY_ASSERT(m_declaration)
-  if(m_declaration->returns().empty())
+  if(not m_declaration)
+  {
+    return Type::Void;
+  } else if(m_declaration->returns().empty())
   {
     return Type::Void;
   } else {

Cauchy/Parser.cpp

       }
       getNextToken(); // eat the ')'
     }
-    const FunctionDeclaration* declaration = d->functionsDefinitionsRegistry->function(functionName, arguments.size(), returns.size());
-    if(declaration)
+    const FunctionDeclaration* declaration = 0;
+    
+    if(d->functionsDefinitionsRegistry)
     {
-      for(std::size_t i = 0; i < arguments.size(); ++i)
+      declaration = d->functionsDefinitionsRegistry->function(functionName, arguments.size(), returns.size());
+      if(declaration)
       {
-        d->variablesManager.getVariable(arguments[i], true)->setType(declaration->arguments()[i]);
+        for(std::size_t i = 0; i < arguments.size(); ++i)
+        {
+          d->variablesManager.getVariable(arguments[i], true)->setType(declaration->arguments()[i]);
+        }
+      } else {
+        reportError("Unknown function: '" + functionName + "'", functionNameTok);
       }
-    } else {
-      reportError("Unknown function: '" + functionName + "'", functionNameTok);
     }
     AST::FunctionDefinition* function = new AST::FunctionDefinition(declaration, returns, arguments);
     while(true)
           }
           return new AST::FunctionCallExpression( variable, arguments, currentLine ) ;
         } else {
-          const FunctionDeclaration* declaration = d->functionsDefinitionsRegistry->function(name, expressionsToType(arguments), currentLine.size());
-          if(declaration)
+          const FunctionDeclaration* declaration = 0;
+          
+          if(d->functionsDefinitionsRegistry)
           {
-            CAUCHY_ASSERT(currentLine.size() <= declaration->returns().size());
-            for(std::size_t i = 0; i < currentLine.size(); ++i)
+            declaration = d->functionsDefinitionsRegistry->function(name, expressionsToType(arguments), currentLine.size());
+            if(declaration)
             {
-              AST::VariableExpression* varExpr = dynamic_cast<AST::VariableExpression*>(currentLine[i]);
-              if(varExpr)
+              CAUCHY_ASSERT(currentLine.size() <= declaration->returns().size());
+              for(std::size_t i = 0; i < currentLine.size(); ++i)
               {
-                varExpr->variable()->setType(declaration->returns()[i]);
-              } else {
-                reportError( "Expect variable name in return expression", currentToken());
+                AST::VariableExpression* varExpr = dynamic_cast<AST::VariableExpression*>(currentLine[i]);
+                if(varExpr)
+                {
+                  varExpr->variable()->setType(declaration->returns()[i]);
+                } else {
+                  reportError( "Expect variable name in return expression", currentToken());
+                }
+                
               }
-              
+            } else if(d->functionsDefinitionsRegistry->function(name).empty()) {
+              reportError("Unknown function '" + name + "'", currentToken());
+            } else {
+              reportError("Invalid number of arguments for function '" + name + "'", currentToken());
             }
-          } else if(d->functionsDefinitionsRegistry->function(name).empty()) {
-            reportError("Unknown function '" + name + "'", currentToken());
-          } else {
-            reportError("Invalid number of arguments for function '" + name + "'", currentToken());
           }
           return new AST::FunctionCallExpression( name, declaration, arguments, currentLine ) ;
         }
       // It can be either a call to a function or a variable access
       String name = d->currentToken.string;
       getNextToken(); // eat the identifier
+      const FunctionDeclaration* declaration = 0;
       if( d->currentToken.type == Token::STARTBRACKET and not d->variablesManager.hasVariable(name) )
       { // It's a function call
         CAUCHY_DEBUG( name );
         getNextToken();
         // Parse arguments
         std::list<AST::Expression*> arguments = parseArguments( );
-        const FunctionDeclaration* declaration = d->functionsDefinitionsRegistry->function(name, expressionsToType(arguments), 0);
-        if(not declaration)
+        
+        if(d->functionsDefinitionsRegistry)
         {
-          if(d->functionsDefinitionsRegistry->function(name).empty()) {
-            reportError("Unknown function '" + name + "'", currentToken());
-          } else {
-            reportError("Invalid number of arguments for function '" + name + "'", currentToken());
+          declaration = d->functionsDefinitionsRegistry->function(name, expressionsToType(arguments), 0);
+          if(not declaration)
+          {
+            if(d->functionsDefinitionsRegistry->function(name).empty()) {
+              reportError("Unknown function '" + name + "'", currentToken());
+            } else {
+              reportError("Invalid number of arguments for function '" + name + "'", currentToken());
+            }
+            return 0;
           }
-          return 0;
-        } else {
-          return new AST::FunctionCallExpression( name, declaration, arguments ) ;
         }
-      } else if(const FunctionDeclaration* declaration = d->functionsDefinitionsRegistry->function(name, std::vector<const Type*>(), 0))
+        return new AST::FunctionCallExpression( name, declaration, arguments ) ;
+      } else if(d->functionsDefinitionsRegistry and (declaration = d->functionsDefinitionsRegistry->function(name, std::vector<const Type*>(), 0)))
       {
         return new AST::FunctionCallExpression(name, declaration, std::list<AST::Expression*>());
       } else {

Cauchy/VariablesManager.cpp

 {
   if(d->globales.find(name) == d->globales.end())
   {
-    const VariableDeclaration* declaration = d->registry->global(name);
-    if(declaration)
+    const VariableDeclaration* declaration = 0;
+    if(d->registry and( declaration = d->registry->global(name)))
     {
       d->globales[name] = new Variable(declaration);
     } else {
   // Maybe it is a constant
   if(d->getVariableInMap( d->constants, name)) {
     return true;
-  } else {
+  } else if(d->registry) {
     // Maybe it is a constant that is not yet in the map
     return d->registry->constant(name);
   }
+  return false;
 }
 
 void VariablesManager::startContext()

tools/m2mml/m2mml.cpp

 {
   Cauchy::String source = _source;
   Cauchy::Source p;
-  Cauchy::DeclarationsRegistry r;
   Cauchy::Options options;
-  p.setSource( "m2mml", source, &r );
+  p.setSource( "m2mml", source, 0 );
   p.compile();
   if(not p.isCompiled())
   {