コード例 #1
0
ファイル: type.cpp プロジェクト: fabianschuiki/Maxwell
/**
 * @brief Returns whether the two types are equal.
 */
bool equal(const NodePtr& a, const NodePtr& b) {

	// Treat combinations of defined types.
	DefinedType::Ptr defTypeA = DefinedType::from(a), defTypeB = DefinedType::from(b);
	if (defTypeA && defTypeB)
		return equal(defTypeA, defTypeB) || equal(defTypeA->getDefinition(), defTypeB->getDefinition());
	if (defTypeA && !defTypeB)
		return equal(defTypeA->getDefinition(), b);
	if (!defTypeA && defTypeB)
		return equal(defTypeB->getDefinition(), a);

	// Resolve type defs.
	TypeDef::Ptr typedefA = TypeDef::from(a), typedefB = TypeDef::from(b);
	if (typedefA && typedefB)
		return equal(typedefA->getType()->needTypeExpr()->getEvaluatedType(), typedefB->getType()->needTypeExpr()->getEvaluatedType());
	if (typedefA && !typedefB)
		return equal(typedefA->getType()->needTypeExpr()->getEvaluatedType(), b);
	if (!typedefA && typedefB)
		return equal(a, typedefB->getType()->needTypeExpr()->getEvaluatedType());

	// Treat qualified types.
	QualifiedType::Ptr qualiTypeA = QualifiedType::from(a), qualiTypeB = QualifiedType::from(b);
	if (qualiTypeA && qualiTypeB)
		return equal(qualiTypeA, qualiTypeB);

	// Treat type sets and unions.
	TypeSet::Ptr typeSetA = TypeSet::from(a), typeSetB = TypeSet::from(b);
	if (typeSetA && typeSetB)
		return equal(typeSetA, typeSetB);
	UnionType::Ptr unionTypeA = UnionType::from(a), unionTypeB = UnionType::from(b);
	if (unionTypeA && unionTypeB)
		return equal(unionTypeA, unionTypeB);

	// Treat specialized types.
	SpecializedType::Ptr specTypeA = SpecializedType::from(a), specTypeB = SpecializedType::from(b);
	if (specTypeA && specTypeB)
		return equal(specTypeA, specTypeB);

	// Treat function types.
	FuncType::Ptr funcTypeA = FuncType::from(a), funcTypeB = FuncType::from(b);
	if (funcTypeA && funcTypeB)
		return equal(funcTypeA, funcTypeB);

	// Treat tuple types.
	TupleType::Ptr tupleTypeA = TupleType::from(a), tupleTypeB = TupleType::from(b);
	if (tupleTypeA && tupleTypeB)
		return equal(tupleTypeA, tupleTypeB);

	// Treat native types.
	auto nativeTypeA = NativeType::from(a);
	auto nativeTypeB = NativeType::from(b);
	if (nativeTypeA && nativeTypeB)
		return equal(nativeTypeA, nativeTypeB);

	return false;
}
コード例 #2
0
void CommonMappingCpp::typedefDecl(const Attributes& attrs, Typedef::Ptr context) {
	static format fmt("typedef %1% %2%;\n");
	const NamePath& path = context->getNamePath();
	if ( 1 == path.size() )
		add( "#if defined(PR_IDL_TYPEDEF)\n\t" );
	add(fmt % /*fullName*/shortName(context->getType()) % shortName(context));
	if ( 1 == path.size() )
		add( "#endif // defined(PR_IDL_TYPEDEF)\n\n" );
}
コード例 #3
0
void CommonMappingC::typedefDecl(const Attributes& attrs, Typedef::Ptr context) {
	static format fmt("typedef %1% %2%;\n");
	add(fmt % fullName(context->getType()) % shortName(context));
}