コード例 #1
0
ファイル: glslOutput.cpp プロジェクト: jims/hlsl2glslfork
bool TGlslOutputTraverser::parseInitializer( TIntermBinary *node )
{
   TIntermTyped *left, *right;

   left = node->getLeft();
   right = node->getRight();

   if (!left->getAsSymbolNode())
      return false; //Something is likely seriously wrong

   TIntermSymbol *symNode = left->getAsSymbolNode();
   

   if (symNode->getBasicType() == EbtStruct)
      return false;

   GlslSymbol * sym = NULL;

   if ( !current->hasSymbol( symNode->getId() ) )
   {
      int array = symNode->getTypePointer()->isArray() ? symNode->getTypePointer()->getArraySize() : 0;
      const char* semantic = "";

      if (symNode->getInfo())
         semantic = symNode->getInfo()->getSemantic().c_str();

      sym = new GlslSymbol( symNode->getSymbol().c_str(), semantic, symNode->getId(),
                            translateType(symNode->getTypePointer()), m_UsePrecision?node->getPrecision():EbpUndefined, translateQualifier(symNode->getQualifier()), array);

      current->addSymbol(sym);
   }
   else
      return false; //can't init already declared variable
	
	if (right->getAsTyped())
	{
		std::stringstream ss;
		std::stringstream* oldOut = &current->getActiveOutput();
		current->pushDepth(0);
		current->setActiveOutput(&ss);
		right->getAsTyped()->traverse(this);
		current->setActiveOutput(oldOut);
		current->popDepth();
		
		sym->setInitializer(ss.str());
	}

   return true;
}
コード例 #2
0
TIntermSymbol *TIntermTraverser::createTempSymbol(const TType &type, TQualifier qualifier)
{
    // Each traversal uses at most one temporary variable, so the index stays the same within a single traversal.
    TInfoSinkBase symbolNameOut;
    ASSERT(mTemporaryIndex != nullptr);
    symbolNameOut << "s" << (*mTemporaryIndex);
    TString symbolName = symbolNameOut.c_str();

    TIntermSymbol *node = new TIntermSymbol(0, symbolName, type);
    node->setInternal(true);
    node->getTypePointer()->setQualifier(qualifier);
    return node;
}
コード例 #3
0
TIntermSymbol *TIntermTraverser::createTempSymbol(const TType &type, TQualifier qualifier)
{
    // Each traversal uses at most one temporary variable, so the index stays the same within a single traversal.
    TInfoSinkBase symbolNameOut;
    ASSERT(mTemporaryIndex != nullptr);
    symbolNameOut << "s" << (*mTemporaryIndex);
    TString symbolName = symbolNameOut.c_str();

    TIntermSymbol *node = new TIntermSymbol(0, symbolName, type);
    node->setInternal(true);

    ASSERT(qualifier == EvqTemporary || qualifier == EvqConst || qualifier == EvqGlobal);
    node->getTypePointer()->setQualifier(qualifier);
    // TODO(oetuaho): Might be useful to sanitize layout qualifier etc. on the type of the created
    // symbol. This might need to be done in other places as well.
    return node;
}
コード例 #4
0
ファイル: Parser.cpp プロジェクト: theomission/kfx
ParsedCode Parser::buildShader(TIntermAggregate* f) {
    cur.pos = f->getLine().first_line;
    cur.args.clear();
    cur.exprs.clear();
    Position pos = f->getLine().first_line;
    TIntermSequence& sequence = f->getSequence();
    TIntermSequence& arguments = sequence[0]->getAsAggregate()->getSequence();
    for (auto it = arguments.begin(); it != arguments.end(); ++it) {
        TIntermSymbol* symbol = (*it)->getAsSymbolNode();
        //if (symbol->getType().getStruct()) {
        //	addConstructor(symbol->getType(), scopedStruct(symbol->getType().getTypeName()), NULL);
        //}
        cur.args.push_back(allocVar(symbol->getQualifierString(), symbol->getTypePointer(), VUnknown, pos));
    }
    parseExpr(sequence[1]->getAsAggregate()->getSequence());
    return cur;
}