Пример #1
0
static  void    ConList( void ) {
//=========================

// Collect constants for data initialization.

    OPR         opr;
    itnode      *last_node;

    opr = FindSlash( &last_node );
    for(;;) {
        if( RecNextOpr( OPR_MUL ) ) {
            ProcDataRepExpr();
            if( ITIntValue( CITNode ) <= 0 ) {
                Error( DA_BAD_RPT_SPEC );
            }
            AddConst( CITNode );
            AdvanceITPtr();
        }
        if( !HexConst() ) {
            GetSConst();
            AddConst( CITNode );
        }
        AdvanceITPtr();
        if( CITNode == last_node )
            break;
        ReqComma();
        if( AError ) {
            break;
        }
    }
    CITNode->opr = opr;
    ReqDiv();
}
Пример #2
0
void    GenExp( TYPE typ ) {
//==========================

    OPTR    op;

    AddConst( CITNode );
    AddConst( CITNode->link );
    op = OPTR_EXP;
    GenOprTable[ op ]( typ, typ, op );
}
Пример #3
0
std::string GLFragmentDecompilerThread::Format(const std::string& code)
{
	const std::pair<std::string, std::function<std::string()>> repl_list[] =
	{
		{ "$$", []() -> std::string { return "$"; } },
		{ "$0", [this]{ return GetSRC<SRC0>(src0); } },
		{ "$1", [this]{ return GetSRC<SRC1>(src1); } },
		{ "$2", [this]{ return GetSRC<SRC2>(src2); } },
		{ "$t", [this]{ return AddTex(); } },
		{ "$m", [this]{ return GetMask(); } },

		{ "$ifcond ", [this]() -> std::string
		{
			const std::string& cond = GetCond();
			if (cond == "true") return "";
			return "if(" + cond + ") ";
		}
		},

		{ "$cond", [this]{ return GetCond(); } },
		{ "$c", [this]{ return AddConst(); } }
	};

	return fmt::replace_all(code, repl_list);
}
Пример #4
0
void            GForceHiBound( int ss, sym_id sym ) {
//=======================================================

// Generate code to fill in ADV subscript element (hi bound).
// The hi bound is constant and the low bound is not.
// We have to force the filling in of the high bound so that the number of
// of elements gets computed.
//
// Scenario:   SUBROUTINE SAM( A, J )
//             DIMENSION A(J:3)
//
// GInitADV() fills in the lo bound and # of elements in the dimension at
// compile-time. The lo bound is unknown so the ADV does not contain the
// correct information. The lo bound gets filled in at run-time but
// since the hi bound is not dumped into the ADV at compile time we
// must fill it in at run-time and compute the correct number of elements
// in the dimension.

    AddConst( CITNode );
    PushOpn( CITNode );
    EmitOp( FC_ADV_FILL_HI );
    OutPtr( sym );
    OutU16( (uint_16)ss );
    GenType( CITNode );
}
Пример #5
0
const boost::shared_ptr<const ribi::foam::Face> ribi::foam::Mesh::FindMostSimilarFace(
  const std::vector<ribi::Coordinat3D>& coordinats
  ) const
{
  ///Obtain the distance from focal coordinats to each face its coordinat
  std::vector<double> distances;
  const std::size_t sz = m_faces.size();
  for (std::size_t i=0; i!=sz; ++i)
  {
    assert(i < m_faces.size());
    assert(m_faces[i]);
    const double distance = CalcSimilarityFaster(
      AddConst(m_faces[i]->GetPoints()),
      coordinats
    );
    TRACE(distance);
    distances.push_back(distance);
  }

  //Find the most similar
  const int index {
    std::distance(
      distances.begin(),
      std::min_element(distances.begin(),distances.end())
    )
  };

  //Return the face
  const boost::shared_ptr<const ribi::foam::Face> p {
    m_faces[index]
  };
  assert(p);
  return p;
}
Пример #6
0
static  void    FoldCatSequence( itnode *cit ) {
//==============================================

// Fold a sequnece of character constants.

    uint        size;
    uint        num;
    itnode      *save;

    save = CITNode;
    CITNode = cit;
    num = 0;
    size = 0;
    for(;;) {
        if( CITNode->opn.us != USOPN_CON ) break;
        num++;
        if( CITNode->typ != FT_CHAR ) {
            TypeErr( MD_ILL_OPR, CITNode->typ );
        } else {
            size += CITNode->value.cstring.len;
        }
        AdvanceITPtr();
        if( CITNode->opr != OPR_CAT ) break;
    }
    if( !AError ) {
        CITNode = cit;
        if( num > 1 ) {
            ConstCat( size );
        } else if( num == 1 ) {
            AddConst( CITNode );
        }
    }
    CITNode = save;
}
Пример #7
0
void    ConstCat( int size ) {
//============================

    itnode      *last_node;
    byte        *dest;
    int         opn_size;
    int         size_left;
    byte        *string;
    itnode      *link_node;

    last_node = CITNode;
    string = FMemAlloc( size );
    size_left = size;
    dest = string;
    for(;;) {
        opn_size = last_node->value.cstring.len;
        memcpy( dest, last_node->value.cstring.strptr, opn_size );
        size_left -= opn_size;
        if( size_left == 0 ) break;
        last_node = last_node->link;
        dest += opn_size;
    }
    CITNode->value.cstring.strptr = (char *)string;
    CITNode->value.cstring.len = size;
    CITNode->size = size;
    link_node = last_node->link;
    last_node->link = NULL;
    FreeITNodes( CITNode->link );
    CITNode->link = link_node;
    AddConst( CITNode );
    CITNode->value.cstring.strptr = (char *)&CITNode->sym_ptr->u.lt.value;
    FMemFree( string );
}
Пример #8
0
long GenModel::AddConst(string cname, double rhs, char sense)
{
	AddConst(cname);
	consts.back().lrhs = rhs;
	consts.back().sense = sense;
	return 0;
}
Пример #9
0
long GenModel::AddModelRow(vector<int>& ind, vector<double>& val, double rhs, char sense, string name)
{
	AddConst(name, rhs, sense);
	for(long i = 0; i < long(ind.size()); i++)
		AddNzToLast(ind[i], val[i]);

	return 0;
}
Пример #10
0
static  void    EvalOpn( void ) {
//===============================

// Evaluate operand.

    if( CITNode->opn.us == USOPN_CON ) {
        AddConst( CITNode );
    }
    PushOpn( CITNode );
}
Пример #11
0
static  void    BreakOpn( FCODE routine ) {
//=========================================

    CITNode->opn.ds = DSOPN_LIT;
    GetConst();
    AddConst( CITNode );
    GBreak( routine );
    AdvanceITPtr();
    if( !RecEOS() ) {
        Error( SX_NUM_OR_LIT );
    }
}
void ribi::cmap::Edge::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  //Test member variables
  TRACE("Started ribi::cmap::Edge::Test");
  {
    const auto nodes = Node::GetTests();
    assert(nodes.size() >= 2);
    const auto node_from = nodes[0];
    const auto node_to   = nodes[1];
    for (const boost::shared_ptr<const cmap::Edge>& edge: EdgeFactory::GetTests(node_from,node_to))
    {
      //Test copy constructor
      assert(edge);
      const boost::shared_ptr<const cmap::Edge> c = cmap::EdgeFactory::DeepCopy(edge,node_from,node_to);
      assert(c);
      assert(*edge == *c);
      assert(*c == *edge);
      assert(*c->GetFrom() == *node_from);
      assert(*c->GetFrom() == *nodes[0]);
      assert(*c->GetTo() == *node_to);
      assert(*c->GetTo() == *nodes[1]);
      const std::string s = ToXml(c,AddConst(nodes));
      const boost::shared_ptr<ribi::cmap::Edge> d = cmap::EdgeFactory::FromXml(s,nodes);
      assert(d);
      if (*c != *d)
      {
        TRACE("ERROR");
        TRACE(ToXml(c,AddConst(nodes)));
        TRACE(ToXml(d,AddConst(nodes)));
      }
      assert(*c == *d);
    }
  }
  TRACE("Edge::Test finished successfully");
}
Пример #13
0
void    FormatIdd( void ) {
//=========================

    cs_label    fmt_label;
    grp_entry   *ge;

    if( RecName() && ( NameListFind() != NULL ) ) {
        BIOutNameList( CITNode->sym_ptr );
        ge = CITNode->sym_ptr->u.nl.group_list;
        while( ge != NULL ) {
            ge->sym->u.ns.flags |= SY_REFERENCED;
            ge = ge->link;
        }
        GSetNameList( FC_SET_NML );
        KWRememb( IO_NAMELIST );
    } else if( RecNumber() ) {
        GPassStmtNo( LkUpFormat(), FC_SET_FMT );
    } else if( RecNOpn() && RecNextOpr( OPR_MUL ) ) {
        if( CITNode->link->opn.ds == DSOPN_PHI ) {
            AdvanceITPtr();   // nothing needs to be loaded for default
            KWRememb( IO_LIST_DIR );
        }
    } else if( RecNOpn() && RecNextOpr( OPR_COM ) ) {
        Extension( IL_NO_ASTERISK );
    } else if( RecIntVar() ) {
        CkVarRef();
        StNumbers.var_format = true;
        GFmtVarSet();
    } else {
        ProcIOExpr();           // will allow for array name alone
        if( !AError ) {
            if( RecArrName() ) {
                if( CITNode->typ != FT_CHAR ) {
                    Extension( IL_NON_CHARACTER );
                }
                ChkAssumed();
                GFmtArrSet();
            } else if( CITNode->typ != FT_CHAR ) {
                Error( IL_BAD_FMT_SPEC );
            } else if( ( CITNode->opn.us == USOPN_CON ) ) {
                AddConst( CITNode ); // in case single constant
                fmt_label.g_label = NextLabel();
                FScan( CITNode->sym_ptr->u.lt.length,
                       (char *)&CITNode->sym_ptr->u.lt.value, fmt_label );
                GPassLabel( fmt_label.g_label, RT_SET_FMT );
            } else {
                GFmtExprSet();
            }
        }
    }
}
Пример #14
0
static  bool    HexConst(void) {
//==========================

// Check for a hexadecimal constant specifier.

    char        *hex_data;
    int         hex_len;
    sym_id      sym;

    hex_data = CITNode->opnd;
    hex_len = CITNode->opnd_size;
    if( CITNode->opn.ds != DSOPN_HEX ) {
        if( !RecName() )
            return( false );
        if( *hex_data != 'Z' )
            return( false );
        sym = SymFind( hex_data, hex_len );
        if( sym != NULL ) {
            if( ( sym->u.ns.flags & SY_CLASS ) == SY_PARAMETER ) {
                return( false );
            }
        }
        ++hex_data;
    }
    --hex_len;
    hex_len = MkHexConst( hex_data, CITNode->opnd, hex_len );
    if( hex_len == 0 )
        return( false );
    CITNode->opnd_size = hex_len;
    CITNode->opn.ds = DSOPN_LIT;
    GetConst();
    AddConst( CITNode );
    CITNode->typ = FT_HEX;
    Extension( DA_HEX_CONST );
    return( true );
}
const std::vector<boost::shared_ptr<const pvdb::Node> > pvdb::ConceptMap::GetNodes() const
{
  return AddConst(m_nodes);
}
const std::vector<boost::shared_ptr<const pvdb::Edge> > pvdb::ConceptMap::GetEdges() const
{
  return AddConst(m_edges);
}
void QtPvdbDisplayConceptItem::UpdateBrushesAndPens()
{
  assert(GetConcept());
  assert(GetConcept()->GetExamples());

  //Brush for the concept being rated
  QBrush new_main_brush = this->brush();
  {
    const int n_rated
      = (GetConcept()->GetRatingComplexity()   != -1 ? 1 : 0)
      + (GetConcept()->GetRatingConcreteness() != -1 ? 1 : 0)
      + (GetConcept()->GetRatingSpecificity()  != -1 ? 1 : 0);
    switch (n_rated)
    {
      case 0:
        new_main_brush = QtPvdbBrushFactory::CreateRedGradientBrush();
        break;
      case 1:
      case 2:
        new_main_brush = QtPvdbBrushFactory::CreateYellowGradientBrush();
        break;
      case 3:
        new_main_brush = QtPvdbBrushFactory::CreateGreenGradientBrush();
        break;
      default: assert(!"Should not get here");
    }
  }
  //Brush and pen for the examples being rated
  QBrush new_indicator_brush = this->GetIndicatorBrush();
  QPen new_indicator_pen = this->GetIndicatorPen();
  if (GetConcept()->GetExamples()->Get().empty())
  {
    //No examples
    new_indicator_brush = QBrush(QColor(0,0,0));
    new_indicator_pen = QPen(QColor(0,0,0));
  }
  else
  {
    const std::vector<boost::shared_ptr<const pvdb::Example> > v = AddConst(GetConcept()->GetExamples()->Get());
    const int n_examples = boost::numeric_cast<int>(v.size());
    const int n_judged
      = std::count_if(v.begin(),v.end(),
        [](const boost::shared_ptr<const pvdb::Example>& p)
        {
          assert(p);
          const pvdb::Competency this_competency = p->GetCompetency();
          return this_competency != pvdb::Competency::uninitialized;
        }
      );
    if (n_judged == 0)
    {
      new_indicator_brush = QBrush(QColor(255,128,128)); //Red
    }
    else if (n_judged < n_examples)
    {
      new_indicator_brush = QBrush(QColor(255,196,128)); //Orange
    }
    else
    {
      assert(n_judged == n_examples);
      new_indicator_brush = QBrush(QColor(128,255,128)); //Green
    }
    if (n_judged == 0)
    {
      new_indicator_pen = QPen(QColor(255,0,0),3); //Thick pen
    }
    else if (n_judged < n_examples)
    {
      new_indicator_pen = QPen(QColor(255,196,0),2); //Less thick pen
    }
    else
    {
      assert(n_judged == n_examples);
      new_indicator_pen = QPen(QColor(0,255,0),1); //Thin pen
    }
  }

  if (this->brush() != new_main_brush
    || this->GetIndicatorBrush() != new_indicator_brush
    || this->GetIndicatorPen() != new_indicator_pen)
  {
    this->setBrush(new_main_brush);
    this->SetIndicatorBrush(new_indicator_brush);
    this->SetIndicatorPen(new_indicator_pen);
    assert(this->brush() == new_main_brush);
    assert(this->GetIndicatorBrush() == new_indicator_brush);
    assert(this->GetIndicatorPen() == new_indicator_pen);
    //TRACE(std::rand()); //GOOD: Detects infinite recursion
    //this->update();
    this->m_signal_item_has_updated(this); //Obligatory
    this->m_signal_request_scene_update(); //Obligatory
  }
}
Пример #18
0
void ribi::foam::Mesh::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  TRACE("Starting ribi::foam::Mesh::Test");
  //Check if the number of boundary faces is correct
  {
    const std::vector<boost::shared_ptr<ribi::foam::Files>> v { Files::CreateTestFiles() };
    assert(v.size() == 6);
    const std::vector<int> n_internal_mesh_faces_expected { 0,0,1,4,12,133 };
    assert(v.size() == n_internal_mesh_faces_expected.size());
    const int n_meshes = static_cast<int>(v.size());
    for (int mesh_index = 0; mesh_index != n_meshes; ++mesh_index)
    {
      const Mesh mesh(*v[mesh_index]);
      const std::vector<boost::shared_ptr<const Face> > mesh_faces {
        mesh.GetFaces()
      };
      const int n_internal {
        std::count_if(mesh_faces.begin(),mesh_faces.end(),
          [](const boost::shared_ptr<const Face> face)
          {
            assert(face);
            assert(face->GetOwner());
            return face->GetNeighbour(); //internal faces have a neighbour
          }
        )
      };
      assert(n_internal == n_internal_mesh_faces_expected[mesh_index]
        && "Must have as much internal faces as expected"
      );
    }
  }
  //CalcSimilarity: empty
  {
    std::vector<boost::shared_ptr<const ribi::Coordinat3D> > v;
    std::vector<ribi::Coordinat3D> w;
    assert(CalcSimilarityFaster(v,w) < 0.001);
  }
  //CalcSimilarity: one point
  {
    std::vector<boost::shared_ptr<const ribi::Coordinat3D> > v;
    std::vector<ribi::Coordinat3D> w;
    {
      const ribi::Coordinat3D c(1.1,2.2,3.3);
      boost::shared_ptr<const ribi::Coordinat3D> d {
        new ribi::Coordinat3D(c)
      };
      assert(c == *d); //Exact comparison
      assert(Distance(c,*d) < 0.0000001); //Fuzzier comparison
      w.push_back(c);
      v.push_back(d);
    }
    assert(CalcSimilarityFaster(v,w) < 0.001);
  }
  //CalcSimilarity: two points
  {
    std::vector<boost::shared_ptr<const ribi::Coordinat3D> > v;
    std::vector<ribi::Coordinat3D> w;
    {
      const ribi::Coordinat3D c(1.1,2.2,3.3);
      boost::shared_ptr<const ribi::Coordinat3D> d {
        new ribi::Coordinat3D(c)
      };
      assert(c == *d); //Exact comparison
      assert(Distance(c,*d) < 0.0000001); //Fuzzier comparison
      w.push_back(c);
      v.push_back(d);
    }
    {
      const ribi::Coordinat3D c(2.2,3.3,4.4);
      boost::shared_ptr<const ribi::Coordinat3D> d {
        new ribi::Coordinat3D(c)
      };
      assert(c == *d); //Exact comparison
      assert(Distance(c,*d) < 0.0000001); //Fuzzier comparison
      w.push_back(c);
      v.push_back(d);
    }
    assert(CalcSimilarityFaster(v,w) < 0.001);
  }
  //CalcSimilarity: one versus two points
  {
    std::vector<boost::shared_ptr<const ribi::Coordinat3D> > v;
    std::vector<ribi::Coordinat3D> w;
    {
      const ribi::Coordinat3D c(1.1,2.2,3.3);
      boost::shared_ptr<const ribi::Coordinat3D> d {
        new ribi::Coordinat3D(c)
      };
      assert(c == *d); //Exact comparison
      assert(Distance(c,*d) < 0.0000001); //Fuzzier comparison
      w.push_back(c);
      v.push_back(d);
    }
    {
      const ribi::Coordinat3D c(2.2,3.3,4.4);
      w.push_back(c);
    }
    assert(CalcSimilarityFaster(v,w) > 1000000000.0);
  }
  //Find most similar Faces
  {
    //Handcraft Faces, put these in mesh

    //For the Points, I used the same setup as in Classes/CppOpenFoam/points_1x1x1:
    //
    // 8((0 0 0) (1 0 0) (0 1 0) (1 1 0) (0 0 1) (1 0 1) (0 1 1) (1 1 1))
    //
    // The order of points is determined by blockMesh
    const boost::shared_ptr<ribi::Coordinat3D> p0 { new ribi::Coordinat3D(0.0,0.0,0.0) };
    const boost::shared_ptr<ribi::Coordinat3D> p1 { new ribi::Coordinat3D(1.0,0.0,0.0) };
    const boost::shared_ptr<ribi::Coordinat3D> p2 { new ribi::Coordinat3D(0.0,1.0,0.0) };
    const boost::shared_ptr<ribi::Coordinat3D> p3 { new ribi::Coordinat3D(1.0,1.0,0.0) };
    const boost::shared_ptr<ribi::Coordinat3D> p4 { new ribi::Coordinat3D(0.0,0.0,1.0) };
    const boost::shared_ptr<ribi::Coordinat3D> p5 { new ribi::Coordinat3D(1.0,0.0,1.0) };
    const boost::shared_ptr<ribi::Coordinat3D> p6 { new ribi::Coordinat3D(0.0,1.0,1.0) };
    const boost::shared_ptr<ribi::Coordinat3D> p7 { new ribi::Coordinat3D(1.0,1.0,1.0) };
    assert(p0); assert(p1); assert(p2); assert(p3);
    assert(p4); assert(p5); assert(p6); assert(p7);
    const boost::shared_ptr<Cell> cell { new Cell };
    const std::vector<boost::shared_ptr<Cell>> cells { cell };

    const boost::shared_ptr<Cell> n0; //No neighbours in a 1x1 mesh
    const boost::shared_ptr<Cell> n1; //No neighbours in a 1x1 mesh
    const boost::shared_ptr<Cell> n2; //No neighbours in a 1x1 mesh
    const boost::shared_ptr<Cell> n3; //No neighbours in a 1x1 mesh
    const boost::shared_ptr<Cell> n4; //No neighbours in a 1x1 mesh
    const boost::shared_ptr<Cell> n5; //No neighbours in a 1x1 mesh
    const boost::shared_ptr<Cell> own0 { cell }; //The only Cell owns all Faces
    const boost::shared_ptr<Cell> own1 { cell }; //The only Cell owns all Faces
    const boost::shared_ptr<Cell> own2 { cell }; //The only Cell owns all Faces
    const boost::shared_ptr<Cell> own3 { cell }; //The only Cell owns all Faces
    const boost::shared_ptr<Cell> own4 { cell }; //The only Cell owns all Faces
    const boost::shared_ptr<Cell> own5 { cell }; //The only Cell owns all Faces

    const std::vector<boost::shared_ptr<ribi::Coordinat3D>> points { p0,p1,p2,p3,p4,p5,p6,p7 };
    //For the Faces, I used the same setup as in Classes/CppOpenFoam/faces_1x1x1:
    //
    //
    //  6
    //  (
    //  4(0 2 3 1)
    //  4(0 4 6 2)
    //  4(0 1 5 4)
    //  4(1 3 7 5)
    //  4(2 6 7 3)
    //  4(4 5 7 6)
    //  )
    //
    // The order of faces is determined by blockMesh
    const boost::shared_ptr<Face> f0 { new Face(n0,own0, { p0, p2, p3, p1 } ) };
    const boost::shared_ptr<Face> f1 { new Face(n1,own1, { p0, p4, p6, p2 } ) };
    const boost::shared_ptr<Face> f2 { new Face(n2,own2, { p0, p1, p5, p4 } ) };
    const boost::shared_ptr<Face> f3 { new Face(n3,own3, { p1, p3, p7, p5 } ) };
    const boost::shared_ptr<Face> f4 { new Face(n4,own4, { p2, p6, p7, p3 } ) };
    const boost::shared_ptr<Face> f5 { new Face(n5,own5, { p4, p5, p7, p6 } ) };

    const std::vector<boost::shared_ptr<Face>> faces { f0,f1,f2,f3,f4,f5 };
    cell->AssignOwnedFaces( { f0,f1,f2,f3,f4,f5 } );

    boost::shared_ptr<Boundary> boundary { new Boundary(  {f0,f1,f2,f3,f4,f5 },"defaultFaces",PatchFieldType::slip ) };
    const std::vector<boost::shared_ptr<Boundary>> boundaries { boundary };

    const Mesh m(
      boundaries,
      cells,
      faces,
      points
    );
    for (const boost::shared_ptr<Face> face: faces)
    {
      assert(face);
      const std::vector<boost::shared_ptr<const ribi::Coordinat3D>> points { AddConst(face->GetPoints()) };
      std::vector<ribi::Coordinat3D> coordinats;
      std::transform(points.begin(),points.end(),
        std::back_inserter(coordinats),
        [](const boost::shared_ptr<const ribi::Coordinat3D> shared_coordinat)
        {
          return ribi::Coordinat3D(*shared_coordinat);
        }
      );
      //For every Face, extract the coordinats
      //FindMostSimilar should find back the original Face
      const boost::shared_ptr<const ribi::foam::Face> result {
        m.FindMostSimilarFace(coordinats)
      };
      assert(result);
      if (face != result)
      {
        TRACE("ERROR");
        TRACE(*face);
        TRACE(*result);
      }
      assert(result == face);
    }
  }
  TRACE("Finished ribi::foam::Mesh::Test successfully");
}
void ribi::trim::SetWindingHorizontal(std::vector<boost::shared_ptr<Edge>>& edges,const Winding winding)
{
  assert(CalcWindingHorizontal(AddConst(edges)) != winding);
  switch(winding)
  {
    case Winding::indeterminate:
    {
      edges[1]->Reverse();
    }
    break;
    case Winding::clockwise:
    {
      assert(edges.size() == 3 && "Otherwise I am not sure this will work");
      const Coordinat3D center { CalcCenter(edges) };
      const int n_edges { static_cast<int>(edges.size()) };
      for (int i=0; i!=n_edges; ++i)
      {
        //Fix winding
        if (!IsClockwiseHorizontal(edges[i],center)) { edges[i]->Reverse(); }
        assert(IsClockwiseHorizontal(edges[i],center));
        //Fix ordering of elements
        if (edges[(i+1) % n_edges]->GetFrom() == edges[i]->GetTo()) continue;
        //Try to swap the next element's order
        assert(i + 1 < n_edges);
        if (edges[i+1]->GetFrom() != edges[i]->GetTo()) { edges[i+1]->Reverse(); }
        if (edges[(i+1) % n_edges]->GetFrom() == edges[i]->GetTo()) continue;
        //Swap the next and its next elements
        assert(i + 2 < n_edges);
        if (edges[i+1]->GetFrom() != edges[i]->GetTo()) { std::swap(edges[i+1],edges[i+2]); }
        if (edges[(i+1) % n_edges]->GetFrom() == edges[i]->GetTo()) continue;
        //Try to swap the next element's order
        if (edges[i+1]->GetFrom() != edges[i]->GetTo()) { edges[i+1]->Reverse(); }
        assert(edges[(i+1) % n_edges]->GetFrom() == edges[i]->GetTo());
      }
    }
    break;
    case Winding::counter_clockwise:
    {
      assert(edges.size() == 3 && "Otherwise I am not sure this will work");
      const Coordinat3D center { CalcCenter(edges) };
      const int n_edges { static_cast<int>(edges.size()) };
      for (int i=0; i!=n_edges; ++i)
      {
        //Fix winding
        if (IsClockwiseHorizontal(edges[i],center)) { edges[i]->Reverse(); }
        assert(!IsClockwiseHorizontal(edges[i],center));
        //Fix ordering of elements
        if (edges[(i+1) % n_edges]->GetFrom() == edges[i]->GetTo()) continue;
        //Try to swap the next element's order
        assert(i + 1 < n_edges);
        if (edges[i+1]->GetFrom() != edges[i]->GetTo()) { edges[i+1]->Reverse(); }
        if (edges[(i+1) % n_edges]->GetFrom() == edges[i]->GetTo()) continue;
        //Swap the next and its next elements
        assert(i + 2 < n_edges);
        if (edges[i+1]->GetFrom() != edges[i]->GetTo()) { std::swap(edges[i+1],edges[i+2]); }
        if (edges[(i+1) % n_edges]->GetFrom() == edges[i]->GetTo()) continue;
        //Try to swap the next element's order
        if (edges[i+1]->GetFrom() != edges[i]->GetTo()) { edges[i+1]->Reverse(); }
        assert(edges[(i+1) % n_edges]->GetFrom() == edges[i]->GetTo());
      }
    }
    break;
  }
  assert(CalcWindingHorizontal(AddConst(edges)) == winding);
}
Пример #20
0
template<typename T> wxString GLFragmentDecompilerThread::GetSRC(T src)
{
	wxString ret = wxEmptyString;

	switch(src.reg_type)
	{
	case 0: //tmp
		ret += AddReg(src.tmp_reg_index, src.fp16);
	break;

	case 1: //input
	{
		static const wxString reg_table[] =
		{
			"gl_Position",
			"col0", "col1",
			"fogc",
			"tc0", "tc1", "tc2", "tc3", "tc4", "tc5", "tc6", "tc7"
		};

		switch(dst.src_attr_reg_num)
		{
		case 0x00: ret += reg_table[0]; break;
		default:
			if(dst.src_attr_reg_num < WXSIZEOF(reg_table))
			{
				ret += m_parr.AddParam(PARAM_IN, "vec4", reg_table[dst.src_attr_reg_num]);
			}
			else
			{
				ConLog.Error("Bad src reg num: %d", dst.src_attr_reg_num);
				ret += m_parr.AddParam(PARAM_IN, "vec4", "unk");
				Emu.Pause();
			}
		break;
		}
	}
	break;

	case 2: //const
		ret += AddConst();
	break;

	default:
		ConLog.Error("Bad src type %d", src.reg_type);
		Emu.Pause();
	break;
	}

	static const char f[4] = {'x', 'y', 'z', 'w'};

	wxString swizzle = wxEmptyString;
	swizzle += f[src.swizzle_x];
	swizzle += f[src.swizzle_y];
	swizzle += f[src.swizzle_z];
	swizzle += f[src.swizzle_w];

	if(strncmp(swizzle, f, 4) != 0) ret += "." + swizzle;

	if(src.abs) ret = "abs(" + ret + ")";
	if(src.neg) ret = "-" + ret;

	return ret;
}
Пример #21
0
void pvdb::Example::Test()
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  TRACE("Starting pvdb::Example::Test");
  //Test of operator== and operator!=
  {
    const int sz = static_cast<int>(pvdb::ExampleFactory::GetTests().size());
    for (int i=0; i!=sz; ++i)
    {
      boost::shared_ptr<const pvdb::Example> a = pvdb::ExampleFactory::GetTests().at(i);
      boost::shared_ptr<      Example> b = pvdb::ExampleFactory::GetTests().at(i);
      assert(a==a); assert(a==b); assert(b==a); assert(b==b);
      for (int j=0; j!=sz; ++j)
      {
        boost::shared_ptr<const pvdb::Example> c = pvdb::ExampleFactory::GetTests().at(j);
        boost::shared_ptr<      Example> d = pvdb::ExampleFactory::GetTests().at(j);
        assert(c==c); assert(c==d); assert(d==c); assert(d==d);
        if (i==j)
        {
          assert(a==c); assert(a==d);
          assert(b==c); assert(b==d);
          assert(c==a); assert(c==b);
          assert(d==a); assert(d==b);
        }
        else
        {
          assert(a!=c); assert(a!=d);
          assert(b!=c); assert(b!=d);
          assert(c!=a); assert(c!=b);
          assert(d!=a); assert(d!=b);
        }
      }
    }
  }
  //Test if unrated and rated examples are noticed as different
  {
    const boost::shared_ptr<pvdb::Example> a = ExampleFactory::Create("1",Competency::misc);
    const boost::shared_ptr<pvdb::Example> b = ExampleFactory::Create("1",Competency::misc);
    const boost::shared_ptr<pvdb::Example> c = ExampleFactory::Create("1",Competency::uninitialized);
    assert(a == a); assert(a == b); assert(a != c);
    assert(b == a); assert(b == b); assert(b != c);
    assert(c != a); assert(c != b); assert(c == c);
  }
  //Conversion between std::string and competency
  {
    const std::vector<Competency> v
      =
      {
        pvdb::Competency::uninitialized,
        pvdb::Competency::profession,
        pvdb::Competency::organisations,
        pvdb::Competency::social_surroundings,
        pvdb::Competency::target_audience,
        pvdb::Competency::ti_knowledge,
        pvdb::Competency::prof_growth,
        pvdb::Competency::misc
      };
    std::vector<std::string> w;
    std::transform(v.begin(),v.end(),std::back_inserter(w),
      [](const pvdb::Competency& c)
      {
        return pvdb::Example::CompetencyToStr(c);
      }
    );
    std::vector<Competency> x;
    std::transform(w.begin(),w.end(),std::back_inserter(x),
      [](const std::string& s)
      {
        return pvdb::Example::StrToCompetency(s);
      }
    );
    assert(v == x);
  }
  //Conversion between class and XML, test for equality
  {
    const std::vector<boost::shared_ptr<const pvdb::Example> > v = AddConst( ::pvdb::ExampleFactory::GetTests());
    std::for_each(v.begin(),v.end(),
      [](const boost::shared_ptr<const pvdb::Example>& e)
      {
        assert(e);
        const std::string s = pvdb::Example::ToXml(e);
        const boost::shared_ptr<const pvdb::Example> f(Example::FromXml(s));
        assert(e == f);
      }
    );
  }
  {
    const std::vector<boost::shared_ptr<const pvdb::Example> > v = AddConst( ::pvdb::ExampleFactory::GetTests());
    const int sz = static_cast<int>(v.size());
    for (int i=0; i!=sz; ++i)
    {
      const boost::shared_ptr<const pvdb::Example>& e = v[i];
      const std::string s = pvdb::Example::ToXml(e);
      for (int j=0; j!=sz; ++j)
      {
        const boost::shared_ptr<const pvdb::Example>& f = v[j];
        const std::string t = pvdb::Example::ToXml(f);
        if (i == j)
        {
          assert(e == f);
          assert(s == t);
        }
        else
        {
          assert(e != f);
          assert(s != t);
        }
      }
    }
  }
  TRACE("Example::Test finished successfully");
}
void QtPvdbRateConceptItem::UpdateBrushesAndPens()
{
  //Brush for the concept being rated
  const int n_rated
    = (GetConcept()->GetRatingComplexity()   != -1 ? 1 : 0)
    + (GetConcept()->GetRatingConcreteness() != -1 ? 1 : 0)
    + (GetConcept()->GetRatingSpecificity()  != -1 ? 1 : 0);

  switch (n_rated)
  {
    case 0:
      this->SetMainBrush(QtPvdbBrushFactory::CreateRedGradientBrush());
      break;
    case 1:
    case 2:
      this->SetMainBrush(QtPvdbBrushFactory::CreateYellowGradientBrush());
      break;
    case 3:
      this->SetMainBrush(QtPvdbBrushFactory::CreateGreenGradientBrush());
      break;
    default: assert(!"Should not get here");
  }
  //Brush and pen for the examples being rated
  if (GetConcept()->GetExamples()->Get().empty())
  {
    //No examples
    this->SetIndicatorBrush(QBrush(QColor(0,0,0)));
    this->SetIndicatorPen(QPen(QColor(0,0,0)));
  }
  else
  {
    const std::vector<boost::shared_ptr<const pvdb::Example> > v = AddConst(GetConcept()->GetExamples()->Get());
    const int n_examples = static_cast<int>(v.size());
    const int n_judged
      = std::count_if(v.begin(),v.end(),
        [](const boost::shared_ptr<const pvdb::Example>& p)
        {
          assert(p);
          const pvdb::Competency this_competency = p->GetCompetency();
          return this_competency != pvdb::Competency::uninitialized;
        }
      );
    if (n_judged == 0)
    {
      this->SetIndicatorBrush(QBrush(QColor(255,128,128)  )); //Red
      this->SetIndicatorPen(  QPen(  QColor(255,  0,  0),3)); //Thick pen
    }
    else if (n_judged < n_examples)
    {
      this->SetIndicatorBrush(QBrush(QColor(255,196,128)  )); //Orange
      this->SetIndicatorPen(  QPen(  QColor(255,196,  0),2)); //Less thick pen
    }
    else
    {
      assert(n_judged == n_examples);
      this->SetIndicatorBrush(QBrush(QColor(128,255,128)  )); //Green
      this->SetIndicatorPen(  QPen(  QColor(  0,255,  0),1)); //Thin pen
    }
  }
  //this->update(); //FIX 2013-01-17
  //this->m_signal_item_has_updated(this); //FIX 2013-01-17
  //this->m_signal_request_scene_update(); //FIX 2013-01-17
}
const std::vector<boost::shared_ptr<const ribi::cmap::Example> > ribi::cmap::Examples::Get() const
{
  return AddConst(m_v);
}
Пример #24
0
static  void    AddSS( int number ) {
//===================================

    MkConst( number );
    AddConst( CITNode );
}
Пример #25
0
template<typename T> std::string FragmentProgramDecompiler::GetSRC(T src)
{
	std::string ret;

	switch (src.reg_type)
	{
	case 0: //tmp
		ret += AddReg(src.tmp_reg_index, src.fp16);
		break;

	case 1: //input
	{
		static const std::string reg_table[] =
		{
			"gl_Position",
			"diff_color", "spec_color",
			"fogc",
			"tc0", "tc1", "tc2", "tc3", "tc4", "tc5", "tc6", "tc7", "tc8", "tc9",
			"ssa"
		};

		switch (dst.src_attr_reg_num)
		{
		case 0x00: ret += reg_table[0]; break;
		default:
			if (dst.src_attr_reg_num < sizeof(reg_table) / sizeof(reg_table[0]))
			{
				ret += m_parr.AddParam(PF_PARAM_IN, getFloatTypeName(4), reg_table[dst.src_attr_reg_num]);
			}
			else
			{
				LOG_ERROR(RSX, "Bad src reg num: %d", u32{ dst.src_attr_reg_num });
				ret += m_parr.AddParam(PF_PARAM_IN, getFloatTypeName(4), "unk");
				Emu.Pause();
			}
			break;
		}
	}
	break;

	case 2: //const
		ret += AddConst();
		break;

	case 3: // ??? Used by a few games, what is it?
		LOG_ERROR(RSX, "Src type 3 used, please report this to a developer.");
		break;

	default:
		LOG_ERROR(RSX, "Bad src type %d", u32{ src.reg_type });
		Emu.Pause();
		break;
	}

	static const char f[4] = { 'x', 'y', 'z', 'w' };

	std::string swizzle = "";
	swizzle += f[src.swizzle_x];
	swizzle += f[src.swizzle_y];
	swizzle += f[src.swizzle_z];
	swizzle += f[src.swizzle_w];

	if (strncmp(swizzle.c_str(), f, 4) != 0) ret += "." + swizzle;

	if (src.abs) ret = "abs(" + ret + ")";
	if (src.neg) ret = "-" + ret;

	return ret;
}
void ribi::cmap::Examples::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  TRACE("Started ribi::cmap::Examples::Test");
  //Test of operator== and operator!=
  {
    const int sz = ExamplesFactory().GetNumberOfTests();
    for (int i=0; i!=sz; ++i)
    {
      boost::shared_ptr<const Examples> a = ExamplesFactory().GetTest(i);
      boost::shared_ptr<      Examples> b = ExamplesFactory().GetTest(i);
      assert(*a == *a);
      assert(*a == *b);
      assert(*b == *a);
      assert(*b == *b);
      for (int j=0; j!=sz; ++j)
      {
        boost::shared_ptr<const Examples> c = ExamplesFactory().GetTest(j);
        boost::shared_ptr<      Examples> d = ExamplesFactory().GetTest(j);
        assert(*c == *c);
        assert(*c == *d);
        assert(*d == *c);
        assert(*d == *d);
        if (i==j)
        {
          assert(*a == *c); assert(*a == *d);
          assert(*b == *c); assert(*b == *d);
          assert(*c == *a); assert(*c == *b);
          assert(*d == *a); assert(*d == *b);
        }
        else
        {
          assert(*a != *c); assert(*a != *d);
          assert(*b != *c); assert(*b != *d);
          assert(*c != *a); assert(*c != *b);
          assert(*d != *a); assert(*d != *b);
        }
      }
    }
  }
  //Conversion between class and XML, test for equality
  {
    const std::vector<boost::shared_ptr<const Examples> > v = AddConst(ExamplesFactory().GetTests());
    std::for_each(v.begin(),v.end(),
      [](const boost::shared_ptr<const Examples>& e)
      {
        assert(e);
        const std::string s { e->ToXml() };
        const boost::shared_ptr<const Examples> f(ExamplesFactory().FromXml(s));
        assert(*e == *f);
      }
    );
  }
  {
    const std::vector<boost::shared_ptr<const Examples> > v = AddConst(ExamplesFactory().GetTests());
    const int sz = boost::numeric_cast<int>(v.size());
    for (int i=0; i!=sz; ++i)
    {
      const boost::shared_ptr<const Examples>& e = v[i];
      const std::string s { e->ToXml() };
      for (int j=0; j!=sz; ++j)
      {
        const boost::shared_ptr<const Examples>& f = v[j];
        const std::string t { f->ToXml() };
        if (i == j)
        {
          assert(*e == *f);
          assert( s ==  t);
        }
        else
        {
          assert(*e != *f);
          assert( s !=  t);
        }
      }
    }
  }
  //Test if unrated and rated examples are noticed as different
  {
    const boost::shared_ptr<Example> a = ExampleFactory::Create("1",Competency::misc);
    const boost::shared_ptr<Example> b = ExampleFactory::Create("1",Competency::misc);
    const boost::shared_ptr<Example> c = ExampleFactory::Create("1",Competency::uninitialized);
    assert(*a == *a); assert(*a == *b); assert(*a != *c);
    assert(*b == *a); assert(*b == *b); assert(*b != *c);
    assert(*c != *a); assert(*c != *b); assert(*c == *c);
    std::vector<boost::shared_ptr<const Example> > v; v.push_back(a);
    std::vector<boost::shared_ptr<const Example> > w; w.push_back(b);
    std::vector<boost::shared_ptr<const Example> > x; x.push_back(c);
    const boost::shared_ptr<Examples> d = ExamplesFactory::Create(v);
    const boost::shared_ptr<Examples> e = ExamplesFactory::Create(w);
    const boost::shared_ptr<Examples> f = ExamplesFactory::Create(x);
    assert(*d == *d); assert(*d == *e); assert(*d != *f);
    assert(*e == *d); assert(*e == *e); assert(*e != *f);
    assert(*f != *d); assert(*f != *e); assert(*f == *f);
  }
  TRACE("Examples::Test finished successfully");
}
Пример #27
0
void ribi::cmap::QtConceptMap::BuildQtConceptMap()
{
  CleanMe();
  assert(m_concept_map);
  assert(m_concept_map->IsValid());
  assert(this->scene());
  //This std::vector keeps the QtNodes in the same order as the nodes in the concept map
  //You cannot rely on Collect<QtConceptMapNodeConcept*>(scene), as this shuffles the order
  std::vector<QtNode*> qtnodes;

  assert(Collect<QtNode>(scene()).empty());

  //Add the nodes to the scene, if there are any
  if (!m_concept_map->GetNodes().empty())
  {
    //Add the main question as the first node
    const boost::shared_ptr<Node> node = m_concept_map->GetFocalNode();

    QtNode * qtnode = nullptr;
    if (IsCenterNode(node))
    {
      const boost::shared_ptr<CenterNode> centernode
        = boost::dynamic_pointer_cast<CenterNode>(node);
      qtnode = new QtCenterNode(centernode);
    }
    else
    {
      qtnode = new QtNode(node,this->GetDisplayStrategy(node->GetConcept()));
    }
    assert(qtnode);
    //Let the center node respond to mouse clicks
    qtnode->m_signal_request_scene_update.connect(
      boost::bind(&ribi::cmap::QtConceptMap::OnRequestSceneUpdate,this));
    qtnode->m_signal_item_has_updated.connect(
      boost::bind(&ribi::cmap::QtConceptMap::OnItemRequestsUpdate,this,boost::lambda::_1));
    //Add the center node to scene
    assert(!qtnode->scene());
    this->scene()->addItem(qtnode);
    qtnodes.push_back(qtnode);
    assert(Collect<QtNode>(scene()).size() == 1);

    //Add the regular nodes to the scene
    const std::vector<boost::shared_ptr<ribi::cmap::Node> > nodes = m_concept_map->GetNodes();
    const std::size_t n_nodes = nodes.size();
    assert(n_nodes >= 1);
    for (std::size_t i=1; i!=n_nodes; ++i) //+1 to skip focal node
    {
      assert(Collect<QtNode>(scene()).size() == i && "Node not yet added to scene");
      assert(i < nodes.size());
      boost::shared_ptr<Node> node = nodes[i];
      assert(node);
      assert( (IsCenterNode(node) || !IsCenterNode(node))
        && "focal node != center node");
      QtNode * const qtnode = AddNode(node);
      qtnodes.push_back(qtnode);
      assert(Collect<QtNode>(scene()).size() == i + 1 && "Node is added to scene");
    }
  }

  #ifndef NDEBUG
  {
    //Check the number of
    const auto qtnodes = Collect<QtNode>(scene());
    const auto n_qtnodes = qtnodes.size();
    const auto nodes = m_concept_map->GetNodes();
    const auto n_nodes = nodes.size();
    assert(n_qtnodes == n_nodes
      && "There must as much nodes in the scene as there were in the concept map");
  }
  #endif
  //Add the Concepts on the Edges
  {
    const std::vector<boost::shared_ptr<ribi::cmap::Edge> > edges = m_concept_map->GetEdges();
    std::for_each(edges.begin(),edges.end(),
      [this,qtnodes](const boost::shared_ptr<Edge> edge)
      {
        assert(edge->GetFrom());
        assert(edge->GetTo());
        assert(edge->GetFrom() != edge->GetTo());
        this->AddEdge(edge);
      }
    );
  }

  #ifndef NDEBUG
  {
    //Check the number of edges
    const auto qtedges = Collect<QtEdge>(scene());
    const auto n_qtedges = qtedges.size();
    const auto edges = m_concept_map->GetEdges();
    const auto n_edges = edges.size();
    assert(n_qtedges == n_edges
      && "There must as much edges in the scene as there were in the concept map");
  }
  #endif

  //Put the nodes around the focal question in an initial position
  if (MustReposition(AddConst(m_concept_map->GetNodes())))
  {
    RepositionItems();
  }

  #ifndef NDEBUG
  assert(m_concept_map->IsValid());
  const auto nodes = m_concept_map->GetNodes();
  const auto items = Collect<QtNode>(this->scene());
  const std::size_t n_items = items.size();
  const std::size_t n_nodes = nodes.size();
  if (n_items != n_nodes)
  {
    TRACE(m_concept_map->GetNodes().size());
    TRACE(n_items);
    TRACE(n_nodes);
  }
  assert(n_items == n_nodes && "GUI and non-GUI concept map must match");
  TestMe(m_concept_map);
  #endif
}
Пример #28
0
static  void    Generate( void ) {
//================================

// Generate code.

    TYPE        typ1;
    TYPE        typ2;
    OPTR        op;
    OPR         opr;
    itnode      *next;
    unsigned_16 mask;
    uint        res_size;

    next = CITNode->link;
    if( next->opn.ds == DSOPN_PHI ) {
        BadSequence();
    } else {
        typ1 = CITNode->typ;
        typ2 = next->typ;
        opr = next->opr;
        if( RecNOpn() ) {
            typ1 = FT_NO_TYPE;
            CITNode->size = next->size;
            if( (opr != OPR_PLS) && (opr != OPR_MIN) && (opr != OPR_NOT) ) {
                BadSequence();
                return;
            }
        }
        op = OprNum[ opr ];
        if( typ1 == FT_NO_TYPE ) {
            mask = LegalOprsU[ typ2 - FT_FIRST ];
        } else {
            mask = LegalOprsB[ ( typ2 - FT_FIRST ) * LEGALOPR_TAB_COLS + typ1 - FT_FIRST ];
        }
        if( (( mask >> ( op - OPTR_FIRST ) ) & 1) == 0 ) {
            // illegal combination
            MoveDown();
            if( typ1 == FT_NO_TYPE ) {
                TypeErr( MD_UNARY_OP, typ2 );
            } else if( typ1 == typ2 ) {
                TypeErr( MD_ILL_OPR, typ1 );
            } else {
                TypeTypeErr( MD_MIXED, typ1, typ2 );
            }
            BackTrack();
        } else if( DoGenerate( typ1, typ2, &res_size ) ) {
            if( ( opr >= OPR_FIRST_RELOP ) && ( opr <= OPR_LAST_RELOP ) &&
                ( (ResultType == FT_COMPLEX) || (ResultType == FT_DCOMPLEX) ||
                (ResultType == FT_XCOMPLEX) ) &&
                ( opr != OPR_EQ ) && ( opr != OPR_NE ) ) {
                // can only compare complex with .EQ. and .NE.
                Error( MD_RELOP_OPND_COMPLEX );
            } else {
                if( ( next->opn.us == USOPN_CON ) &&
                    ( ( CITNode->opn.us == USOPN_CON ) || ( typ1 == FT_NO_TYPE ) ) ) {
                    // we can do some constant folding
                    ConstTable[ op ]( typ1, typ2, op );
                } else {
                    // we have to generate code
                    if( CITNode->opn.us == USOPN_CON ) {
                        AddConst( CITNode );
                    } else if( next->opn.us == USOPN_CON ) {
                        AddConst( next );
                    }
                    GenOprTable[ op ]( typ1, typ2, op );
                }
            }
            switch( opr ) {
            case OPR_EQV:
            case OPR_NEQV:
            case OPR_OR:
            case OPR_AND:
            case OPR_NOT:
                if( _IsTypeInteger( typ1 ) ) {
                    Extension( MD_LOGOPR_INTOPN );
                }
                break;
            case OPR_EQ:        // relational operators
            case OPR_NE:
            case OPR_LT:
            case OPR_GE:
            case OPR_LE:
            case OPR_GT:
                ResultType = FT_LOGICAL;
                res_size = TypeSize( ResultType );
                break;
            case OPR_FLD:
            case OPR_DPT:
                // set result size to size of field
                res_size = next->size;
                FixFldNode();
                break;
            }
            CITNode->size = res_size;
            CITNode->typ = ResultType;
            FixList();
        }
    }
Пример #29
0
template<typename T> std::string GLFragmentDecompilerThread::GetSRC(T src)
{
	std::string ret;

	switch(src.reg_type)
	{
	case 0: //tmp
		ret += AddReg(src.tmp_reg_index, src.fp16);
	break;

	case 1: //input
	{
		static const std::string reg_table[] =
		{
			"gl_Position",
			"diff_color", "spec_color",
			"fogc",
			"tc0", "tc1", "tc2", "tc3", "tc4", "tc5", "tc6", "tc7", "tc8", "tc9",
			"ssa"
		};

		switch(dst.src_attr_reg_num)
		{
		case 0x00: ret += reg_table[0]; break;
		default:
			if(dst.src_attr_reg_num < sizeof(reg_table)/sizeof(reg_table[0]))
			{
				ret += m_parr.AddParam(PARAM_IN, "vec4", reg_table[dst.src_attr_reg_num]);
			}
			else
			{
				ConLog.Error("Bad src reg num: %d", fmt::by_value(dst.src_attr_reg_num));
				ret += m_parr.AddParam(PARAM_IN, "vec4", "unk");
				Emu.Pause();
			}
		break;
		}
	}
	break;

	case 2: //const
		ret += AddConst();
	break;

	default:
		ConLog.Error("Bad src type %d", fmt::by_value(src.reg_type));
		Emu.Pause();
	break;
	}

	static const char f[4] = {'x', 'y', 'z', 'w'};

	std::string swizzle = "";
	swizzle += f[src.swizzle_x];
	swizzle += f[src.swizzle_y];
	swizzle += f[src.swizzle_z];
	swizzle += f[src.swizzle_w];

	if(strncmp(swizzle.c_str(), f, 4) != 0) ret += "." + swizzle;

	if(src.abs) ret = "abs(" + ret + ")";
	if(src.neg) ret = "-" + ret;

	return ret;
}
void QtPvdbRatingDialog::DisplayValues(
  const boost::shared_ptr<const pvdb::File> file,
  QTableWidget * const table)
{
  std::vector<boost::shared_ptr<const pvdb::Node> > all_nodes = AddConst(file->GetConceptMap()->GetNodes());
  #ifndef NDEBUG
  const int all_sz = static_cast<int>(all_nodes.size());
  #endif

  all_nodes.erase(all_nodes.begin());

  #ifndef NDEBUG
  const int sz = static_cast<int>(all_nodes.size());
  assert(sz == all_sz - 1);
  #endif

  const std::vector<boost::shared_ptr<const pvdb::Node> > nodes = all_nodes;
  const int n_nodes = static_cast<int>(nodes.size());  //Constant 'c'
  //Concreteness experimental: C_e at row = 1, col = 0
  //50.0 * sum_rated_concreteness / n_nodes
  {
    const int sum_rated_concreteness //Constant 'k_c'
      = std::accumulate(nodes.begin(),nodes.end(),0,
      [](int& init, const boost::shared_ptr<const pvdb::Node>& node)
      {
        return init + node->GetConcept()->GetRatingConcreteness();
      }
    );
    std::string text = "N/A";
    if (n_nodes != 0)
    {
      const int c_e
        = static_cast<int>(
          std::round(
           50.0 * static_cast<double>(sum_rated_concreteness)
            / static_cast<double>(n_nodes)
          )
        );
      text = boost::lexical_cast<std::string>(c_e);
    }
    QTableWidgetItem * const item = new QTableWidgetItem;
    item->setText(text.c_str());
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    table->setItem(1,0,item);
  }
  //Concreteness eStimated: C_s at row = 1, col = 1
  //C_s = 100.0 * n_examples / (n_examples + n_nodes + n_relations_not_to_focus)
  {
    const std::vector<boost::shared_ptr<const pvdb::Edge> > edges = AddConst(file->GetConceptMap()->GetEdges());
    const int n_nodes_examples = std::accumulate(nodes.begin(),nodes.end(),0,
      [](int& init, const boost::shared_ptr<const pvdb::Node>& node)
      {
        return init + static_cast<int>(node->GetConcept()->GetExamples()->Get().size());
      }
    );
    const int n_edges_examples = std::accumulate(edges.begin(),edges.end(),0,
      [](int& init, const boost::shared_ptr<const pvdb::Edge>& edge)
      {
        return init + static_cast<int>(edge->GetConcept()->GetExamples()->Get().size());
      }
    );
    const int n_relations_not_to_focus //Constant 'r'
      = std::count_if(edges.begin(),edges.end(),
      [](const boost::shared_ptr<const pvdb::Edge>& edge)
      {
        return edge->GetFrom() != 0 && edge->GetTo() != 0; //Not connected to focus question
      }
    );
    const int n_examples //Constant 'v'
      = n_nodes_examples + n_edges_examples;
    std::string text = "N/A";
    if (n_examples + n_nodes + n_relations_not_to_focus != 0)
    {
      const double c_s
        = static_cast<int>(
          std::round(
            100.0 * static_cast<double>(n_examples)
            / static_cast<double>(n_examples + n_nodes + n_relations_not_to_focus)
          )
        );
      text = boost::lexical_cast<std::string>(c_s);
    }
    QTableWidgetItem * const item = new QTableWidgetItem;
    item->setText(text.c_str());
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    table->setItem(1,1,item);
  }
  //Complexity experimental value: X_e at row = 0, col = 0
  //50.0 * sum_rated_complexity / n_nodes
  {
    const int sum_rated_complexity //Constant 'k_i'
      = std::accumulate(nodes.begin(),nodes.end(),0,
      [](int& init, const boost::shared_ptr<const pvdb::Node>& node)
      {
        return init + node->GetConcept()->GetRatingComplexity();
      }
    );
    std::string text = "N/A";
    if (n_nodes != 0)
    {
      const int x_e
        = static_cast<int>(
          std::round(
           50.0 * static_cast<double>(sum_rated_complexity)
            / static_cast<double>(n_nodes)
          )
        );
      text = boost::lexical_cast<std::string>(x_e);
    }
    QTableWidgetItem * const item = new QTableWidgetItem;
    item->setText(text.c_str());
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    table->setItem(0,0,item);
  }
  //compleXity eStimated: X_s at row = 0, col = 1
  //x_s = ((2*n_relations_not_to_focus)/(n_nodes*(n_nodes-1))))^0.25*100%
  {
    const std::vector<boost::shared_ptr<const pvdb::Edge> > edges = AddConst(file->GetConceptMap()->GetEdges());
    const int n_relations_not_to_focus //Constant 'r'
      = std::count_if(edges.begin(),edges.end(),
      [](const boost::shared_ptr<const pvdb::Edge>& edge)
      {
        return edge->GetFrom() != 0 && edge->GetTo() != 0; //Not connected to focus question
      }
    );
    std::string text = "N/A";
    if (n_nodes > 1)
    {
      const int x_s
        = static_cast<int>(
            std::round(
              100.0
              * std::pow(
                  static_cast<double>(n_relations_not_to_focus * 2)
                / static_cast<double>(n_nodes * (n_nodes - 1) ),
                0.25)
            )
          );
       text = boost::lexical_cast<std::string>(x_s);
     }
    QTableWidgetItem * const item = new QTableWidgetItem;
    item->setText(text.c_str());
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    table->setItem(0,1,item);
  }
  //Experimental specificity: s_e at row = 2, col = 0
  //s_e = 50.0 * sum_rated_specificity / n_nodes
  {
    const int sum_rated_specificity //Constant 'k_s'
      = std::accumulate(nodes.begin(),nodes.end(),0,
      [](int& init, const boost::shared_ptr<const pvdb::Node>& node)
      {
        return init + node->GetConcept()->GetRatingSpecificity();
      }
    );
    std::string text = "N/A";
    if (n_nodes != 0)
    {
      const int s_e
        = static_cast<int>(
          std::round(
            static_cast<double>(50 * sum_rated_specificity)
            / static_cast<double>(n_nodes)
          )
        );
      text = boost::lexical_cast<std::string>(s_e);
    }
    QTableWidgetItem * const item = new QTableWidgetItem;
    item->setText(text.c_str());
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    table->setItem(2,0,item);
  }
  //Richness Experimental: r_e at row = 3, col = 0
  //r_e = ((a + b) / 14) * 100%
  //a = number of different Competencies
  //b = number of Competencies between 1/12th and 1/4th of number of examples
  {
    std::map<pvdb::Competency,int> m;
    //Tally the competencies
    for (const boost::shared_ptr<const pvdb::Node>& node: nodes)
    {
      for (const boost::shared_ptr<const pvdb::Example> example: node->GetConcept()->GetExamples()->Get())
      {
        const pvdb::Competency competency = example->GetCompetency();
        const auto iter = m.find(competency);
        if (iter != m.end())
        {
          ++(*iter).second; //Tally the known competency
        }
        else
        {
          m.insert(std::make_pair(competency,1)); //Tally the first of this competency
        }
      }
    }
    //Remove category 'misc'
    #ifndef NDEBUG
    const int debug_m_size_old = static_cast<int>(m.size());
    const bool debug_will_resize = m.count(pvdb::Competency::misc);
    #endif
    m.erase(pvdb::Competency::misc);
    #ifndef NDEBUG
    const int debug_m_size_new = static_cast<int>(m.size());
    assert( ( debug_will_resize && debug_m_size_old == debug_m_size_new + 1)
         || (!debug_will_resize && debug_m_size_old == debug_m_size_new    )
    );
    #endif


    const int a = static_cast<int>(m.size());
    const int n_examples = std::accumulate(m.begin(),m.end(),0,
      [](int& init,const std::pair<pvdb::Competency,int>& p)
      {
        return init + p.second;
      }
    );
    const int my_min = static_cast<int>(std::ceil( static_cast<double>(n_examples) / 12.0));
    const int my_max = static_cast<int>(std::floor(static_cast<double>(n_examples) /  4.0));
    const int b = std::count_if(m.begin(),m.end(),
      [my_min,my_max](const std::pair<pvdb::Competency,int>& p)
      {
        return p.second >= my_min && p.second <= my_max;
      }
    );

    const int r_e
      = static_cast<int>(
        std::round(
          100.0 * ( static_cast<double>(a+b) / 12.0)
        )
      );
    std::string text = boost::lexical_cast<std::string>(r_e);
    QTableWidgetItem * const item = new QTableWidgetItem;
    item->setText(text.c_str());
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    table->setItem(3,0,item);
  }
  table->verticalHeader()->setMaximumWidth(100);
  table->verticalHeader()->setMinimumWidth(100);
  table->setColumnWidth(0,200);
  table->setColumnWidth(1,200);
  assert(table->verticalHeader()->width() == 100);
  table->setMaximumWidth(
      table->verticalHeader()->width()
    + table->columnWidth(0)
    + table->columnWidth(1)
  );
}