Edit

kc3-lang/angle/src/compiler/MapLongVariableNames.cpp

Branch :

  • Show log

    Commit

  • Author : zmo@google.com
    Date : 2011-06-17 22:31:32
    Hash : 216aa5ed
    Message : Map long for-loop control variable names in shaders. Look at TIntermLoop::traverse() in IntermTraverse.cpp, the control init part is not handled explicitly there (unlike the other two parts). It is expected hat visitLoop will cover the init part. The bug in the MapLongVariableNames is that the visitLoop doesn't do anything. This CL fixes it. BUG=171 TEST=conformance/glsl-long-variable-names.html passing. Review URL: http://codereview.appspot.com/4644045 git-svn-id: https://angleproject.googlecode.com/svn/trunk@696 736b8ea6-26fd-11df-bfd4-992fa37f6226

  • src/compiler/MapLongVariableNames.cpp
  • //
    // Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    #include "compiler/MapLongVariableNames.h"
    
    namespace {
    
    TString mapLongName(int id, const TString& name, bool isVarying)
    {
        ASSERT(name.size() > MAX_IDENTIFIER_NAME_SIZE);
        TStringStream stream;
        stream << "webgl_";
        if (isVarying)
            stream << "v";
        stream << id << "_";
        stream << name.substr(0, MAX_IDENTIFIER_NAME_SIZE - stream.str().size());
        return stream.str();
    }
    
    }  // anonymous namespace
    
    MapLongVariableNames::MapLongVariableNames(
        TMap<TString, TString>& varyingLongNameMap)
        : mVaryingLongNameMap(varyingLongNameMap)
    {
    }
    
    void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
    {
        ASSERT(symbol != NULL);
        if (symbol->getSymbol().size() > MAX_IDENTIFIER_NAME_SIZE) {
            switch (symbol->getQualifier()) {
              case EvqVaryingIn:
              case EvqVaryingOut:
              case EvqInvariantVaryingIn:
              case EvqInvariantVaryingOut:
                symbol->setSymbol(
                    mapVaryingLongName(symbol->getSymbol()));
                break;
              default:
                symbol->setSymbol(
                    mapLongName(symbol->getId(), symbol->getSymbol(), false));
                break;
            };
        }
    }
    
    void MapLongVariableNames::visitConstantUnion(TIntermConstantUnion*)
    {
    }
    
    bool MapLongVariableNames::visitBinary(Visit, TIntermBinary*)
    {
        return true;
    }
    
    bool MapLongVariableNames::visitUnary(Visit, TIntermUnary*)
    {
        return true;
    }
    
    bool MapLongVariableNames::visitSelection(Visit, TIntermSelection*)
    {
        return true;
    }
    
    bool MapLongVariableNames::visitAggregate(Visit, TIntermAggregate*)
    {
        return true;
    }
    
    bool MapLongVariableNames::visitLoop(Visit, TIntermLoop* node)
    {
        if (node->getInit())
            node->getInit()->traverse(this);
        return true;
    }
    
    bool MapLongVariableNames::visitBranch(Visit, TIntermBranch*)
    {
        return true;
    }
    
    TString MapLongVariableNames::mapVaryingLongName(const TString& name)
    {
        TMap<TString, TString>::const_iterator it = mVaryingLongNameMap.find(name);
        if (it != mVaryingLongNameMap.end())
            return (*it).second;
    
        int id = mVaryingLongNameMap.size();
        TString mappedName = mapLongName(id, name, true);
        mVaryingLongNameMap.insert(
            TMap<TString, TString>::value_type(name, mappedName));
        return mappedName;
    }