Exemplo n.º 1
0
int GaterVertex::sortCmp(const V3GraphVertex* rhsp) const {
    const GaterVertex* crhsp = static_cast<const GaterVertex*>(rhsp);
    // We really only care about ordering Var's together, but...
    // First put same type together
    if (typeNum() < crhsp->typeNum()) return -1;
    if (typeNum() > crhsp->typeNum()) return 1;
    // If variable, group by same input fanin
    // (know they're the same type based on above compare)
    if (dynamic_cast<const GaterVarVertex*>(this)) {
	// We've already sorted by edges, so just see if same tree
	// If this gets too slow, we could compute a hash up front
	V3GraphEdge* lEdgep = this->inBeginp();
	V3GraphEdge* rEdgep = rhsp->inBeginp();
	while (lEdgep && rEdgep) {
	    const GaterEdge* clEdgep = static_cast<const GaterEdge*>(lEdgep);
	    const GaterEdge* crEdgep = static_cast<const GaterEdge*>(rEdgep);
	    if (lEdgep->fromp()->rank() < rEdgep->fromp()->rank()) return -1;
	    if (lEdgep->fromp()->rank() > rEdgep->fromp()->rank()) return 1;
	    if (clEdgep->ifelse() < crEdgep->ifelse()) return -1;
	    if (clEdgep->ifelse() > crEdgep->ifelse()) return 1;
	    lEdgep = lEdgep->inNextp();
	    rEdgep = rEdgep->inNextp();
	}
	if (!lEdgep && !rEdgep) return 0;
	return lEdgep ? -1 : 1;
    }
    // Finally by rank of this vertex
    if (rank() < rhsp->rank()) return -1;
    if (rank() > rhsp->rank()) return 1;
    return 0;
}
Exemplo n.º 2
0
////////////////////////////////////////////////////////////////////////////////
// parse - parses a declaration (s.a. TIntermediateRenderer::declare() for syntax
//         of type)
//
// Parameters:
//   name  - optional name of the declaration (case sensitive)
//   type  - type description of the declaration
//   isDef - true if the declarition a default declaration of the renderer
//
// Returns:
//   false - type could not be parsed
//
bool TParameterDeclaration::parse(const char *name, const char *type, bool isDef) {

	m_isDefault = isDef;

	m_name = name ? name : "";
	m_fullname = type ? type : m_name.c_str();
	m_isInline = false;

	if ( type ) {
		size_t pos = 0;
		while ( *type && isspace(*type) )
			++type;

		m_class = classNum(type, pos);
		if ( m_class )
			type += pos;
		else
			m_class = CLASS_UNIFORM;

		pos = 0;
		while ( *type && isspace(*type) )
			++type;

		m_type = typeNum(type, pos);
		if ( m_type )
			type += pos;

		/*
		else // if there is no default type (== 0)
			return false;
		*/

		pos = 0;
		while ( *type && isspace(*type) )
			++type;

		m_cardinality = cardinality(type, pos);
		if ( m_cardinality >= 1 )
			type += pos;
		else
			m_cardinality = 1;

		pos = 0;
		while ( *type && isspace(*type) )
			++type;

		if ( !name || !*name ) {
			// RI_TOKEN name
			while ( *type && !isspace(*type) ) {
				if ( !m_isInline ) {
					m_name = "";
					m_isInline = true;
				}
				m_name += *type;
				++type;
			}
			if ( !m_name.length() )
				return false;
		}

		// now only white space should follow
		while ( *type ) {
			if ( !isspace(*type) )
				return false;
			++type;
		}

	} else {
		m_class = 0;
		m_type = 0;
		m_cardinality = 0;
	}

	buildFullname();
	return true;
}