[opengtl-commits] [409] parse dependent

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


Revision: 409
Author:   cyrille
Date:     2008-09-21 09:27:58 +0200 (Sun, 21 Sep 2008)

Log Message:
-----------
parse dependent
report as unexpected when accessing the member of a non structure

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Token_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Token_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Lexer_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp	2008-09-21 06:41:27 UTC (rev 408)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp	2008-09-21 07:27:58 UTC (rev 409)
@@ -52,7 +52,11 @@
 {
   GTLCore::GenerationContext gc( _codeGenerator, 0, 0, _module);
   
-  llvm::Constant* value = _codeGenerator->convertConstantTo( m_initialiser->generateValue( gc, 0 ).constant(), m_initialiser->type() , m_type );
+  llvm::Constant* value = 0;
+  if( m_initialiser )
+  {
+    _codeGenerator->convertConstantTo( m_initialiser->generateValue( gc, 0 ).constant(), m_initialiser->type() , m_type );
+  }
   llvm::Value* pointer = new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _module->llvmModule() );
   m_variable->initialise( gc, 0, pointer);
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Token_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Token_p.cpp	2008-09-21 06:41:27 UTC (rev 408)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Token_p.cpp	2008-09-21 07:27:58 UTC (rev 409)
@@ -179,6 +179,8 @@
       return "uniform";
     case VARYING:
       return "varying";
+    case DEPENDENT:
+      return "dependent";
     case TTRUE:
       return "true";
     case TFALSE:

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Token_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Token_p.h	2008-09-21 06:41:27 UTC (rev 408)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Token_p.h	2008-09-21 07:27:58 UTC (rev 409)
@@ -116,6 +116,7 @@
       VARYING,
       TTRUE,
       TFALSE,
+      DEPENDENT
     };
     /// type of the token
     Type type;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Lexer_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Lexer_p.cpp	2008-09-21 06:41:27 UTC (rev 408)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Lexer_p.cpp	2008-09-21 07:27:58 UTC (rev 409)
@@ -85,6 +85,7 @@
     IDENTIFIER_IS_KEYWORD( "print", PRINT );
     IDENTIFIER_IS_KEYWORD( "true", TTRUE );
     IDENTIFIER_IS_KEYWORD( "false", TFALSE );
+    IDENTIFIER_IS_KEYWORD( "dependent", DEPENDENT );
     return GTLCore::Token(GTLCore::Token::IDENTIFIER, identifierStr,line(), initial_col);
   } else if( isdigit(lastChar) )
   { // if it's a digit 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-09-21 06:41:27 UTC (rev 408)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp	2008-09-21 07:27:58 UTC (rev 409)
@@ -26,6 +26,7 @@
 
 #include <GTLCore/AST/Statement.h>
 #include <GTLCore/AST/Tree.h>
+#include <GTLCore/CompilerBase_p.h>
 #include <GTLCore/TypeManager.h>
 #include <GTLCore/VariablesManager_p.h>
 
@@ -35,11 +36,13 @@
 struct Parser::Private {
   GTLCore::String kernelName;
   GTLCore::AST::Tree* tree;
+  GTLCore::CompilerBase* compiler;
 };
 
 Parser::Parser( Compiler* _compiler , Lexer* _lexer) : ParserBase(_compiler, _lexer), d(new Private)
 {
   d->tree = 0;
+  d->compiler = _compiler;
 }
 
 Parser::~Parser()
@@ -89,6 +92,9 @@
       case GTLCore::Token::STRUCT:
         parseStructDefinition();
         break;
+      case GTLCore::Token::DEPENDENT:
+        parseDependentDeclaration();
+        break;
       default:
       {
         if( currentToken().isFunctionType() )
@@ -187,3 +193,33 @@
       return GTLCore::ParserBase::parseType();
   }
 }
+
+void Parser::parseDependentDeclaration()
+{
+  getNextToken();
+  const GTLCore::Type* type = parseType();
+  if( isOfType( currentToken(), GTLCore::Token::IDENTIFIER ) )
+  {
+    GTLCore::String name = currentToken().string;
+    getNextToken();
+    std::list<int> memberArraySize = expressionsListToIntegersList( parseArraySize(true) );
+    type = d->compiler->typeManager()->getArray( type, memberArraySize.size() );
+    if( isOfType( currentToken(), GTLCore::Token::SEMI ) )
+    {
+      getNextToken();
+      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 , 0 );
+        variablesManager()->declareConstant( scopedName, gcd->variable() );
+        tree()->append( gcd );
+      }
+    }
+  } else {
+    GTL_DEBUG("Unexpected");
+    reportUnexpected( currentToken() );
+    reachNextSemi();
+  }
+}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.h	2008-09-21 06:41:27 UTC (rev 408)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.h	2008-09-21 07:27:58 UTC (rev 409)
@@ -41,6 +41,7 @@
       virtual GTLCore::AST::Statement* parseStatement();
       virtual const GTLCore::Type* parseType();
     private:
+      void parseDependentDeclaration();
       void parseKernelBody();
     private:
       struct Private;


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