LCOV - code coverage report
Current view: top level - gfx/angle/src/compiler/translator - RegenerateStructNames.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 30 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
       3             : // Use of this source code is governed by a BSD-style license that can be
       4             : // found in the LICENSE file.
       5             : //
       6             : 
       7             : #include "common/debug.h"
       8             : #include "compiler/translator/RegenerateStructNames.h"
       9             : 
      10             : namespace sh
      11             : {
      12             : 
      13           0 : void RegenerateStructNames::visitSymbol(TIntermSymbol *symbol)
      14             : {
      15           0 :     ASSERT(symbol);
      16           0 :     TType *type = symbol->getTypePointer();
      17           0 :     ASSERT(type);
      18           0 :     TStructure *userType = type->getStruct();
      19           0 :     if (!userType)
      20           0 :         return;
      21             : 
      22           0 :     if (mSymbolTable.findBuiltIn(userType->name(), mShaderVersion))
      23             :     {
      24             :         // Built-in struct, do not touch it.
      25           0 :         return;
      26             :     }
      27             : 
      28           0 :     int uniqueId = userType->uniqueId();
      29             : 
      30           0 :     ASSERT(mScopeDepth > 0);
      31           0 :     if (mScopeDepth == 1)
      32             :     {
      33             :         // If a struct is defined at global scope, we don't map its name.
      34             :         // This is because at global level, the struct might be used to
      35             :         // declare a uniform, so the same name needs to stay the same for
      36             :         // vertex/fragment shaders. However, our mapping uses internal ID,
      37             :         // which will be different for the same struct in vertex/fragment
      38             :         // shaders.
      39             :         // This is OK because names for any structs defined in other scopes
      40             :         // will begin with "_webgl", which is reserved. So there will be
      41             :         // no conflicts among unmapped struct names from global scope and
      42             :         // mapped struct names from other scopes.
      43             :         // However, we need to keep track of these global structs, so if a
      44             :         // variable is used in a local scope, we don't try to modify the
      45             :         // struct name through that variable.
      46           0 :         mDeclaredGlobalStructs.insert(uniqueId);
      47           0 :         return;
      48             :     }
      49           0 :     if (mDeclaredGlobalStructs.count(uniqueId) > 0)
      50           0 :         return;
      51             :     // Map {name} to _webgl_struct_{uniqueId}_{name}.
      52           0 :     const char kPrefix[] = "_webgl_struct_";
      53           0 :     if (userType->name().find(kPrefix) == 0)
      54             :     {
      55             :         // The name has already been regenerated.
      56           0 :         return;
      57             :     }
      58           0 :     std::string id = Str(uniqueId);
      59           0 :     TString tmp = kPrefix + TString(id.c_str());
      60           0 :     tmp += "_" + userType->name();
      61           0 :     userType->setName(tmp);
      62             : }
      63             : 
      64           0 : bool RegenerateStructNames::visitBlock(Visit, TIntermBlock *block)
      65             : {
      66           0 :     ++mScopeDepth;
      67           0 :     TIntermSequence &sequence = *(block->getSequence());
      68           0 :     for (TIntermNode *node : sequence)
      69             :     {
      70           0 :         node->traverse(this);
      71             :     }
      72           0 :     --mScopeDepth;
      73           0 :     return false;
      74             : }
      75             : 
      76             : }  // namespace sh

Generated by: LCOV version 1.13