00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "TypeEqual.h"
00010
00011 using namespace comma;
00012 using llvm::dyn_cast;
00013 using llvm::isa;
00014
00015 bool comma::compareTypesUsingRewrites(const AstRewriter &rewrites,
00016 SignatureType *typeX,
00017 SignatureType *typeY)
00018 {
00019 if (typeX->getDeclaration() == typeY->getDeclaration()) {
00020 if (typeX->isParameterized()) {
00021 unsigned arity = typeX->getArity();
00022 for (unsigned i = 0; i < arity; ++i) {
00023 DomainType *argX = typeX->getActualParameter(i);
00024 DomainType *argY = typeY->getActualParameter(i);
00025 if (!compareTypesUsingRewrites(rewrites, argX, argY))
00026 return false;
00027 }
00028 }
00029 return true;
00030 }
00031 return false;
00032 }
00033
00034 bool comma::compareTypesUsingRewrites(const AstRewriter &rewrites,
00035 DomainType *typeX,
00036 DomainType *typeY)
00037 {
00038 typeX = rewrites.getRewrite(typeX);
00039 typeY = rewrites.getRewrite(typeY);
00040
00041 if (typeX == typeY)
00042 return true;
00043
00044
00045
00046
00047 if (typeX->getDeclaration() == typeY->getDeclaration()) {
00048 ConcreteDomainType *domX = typeX->getConcreteType();
00049 ConcreteDomainType *domY = typeY->getConcreteType();
00050
00051 if (!(domX && domY))
00052 return false;
00053
00054 if (!(domX->isParameterized() && domY->isParameterized()))
00055 return false;
00056
00057
00058
00059 unsigned arity = domX->getArity();
00060 for (unsigned i = 0; i < arity; ++i) {
00061 DomainType *argX = domX->getActualParameter(i);
00062 DomainType *argY = domY->getActualParameter(i);
00063 if (!compareTypesUsingRewrites(rewrites, argX, argY))
00064 return false;
00065 }
00066 return true;
00067 }
00068 return false;
00069 }
00070
00071 bool comma::compareTypesUsingRewrites(const AstRewriter &rewrites,
00072 FunctionType *typeX,
00073 FunctionType *typeY)
00074 {
00075 unsigned arity = typeX->getArity();
00076
00077 if (arity != typeY->getArity())
00078 return false;
00079
00080 if (!compareTypesUsingRewrites(rewrites,
00081 typeX->getReturnType(),
00082 typeY->getReturnType()))
00083 return false;
00084
00085 for (unsigned i = 0; i < arity; ++i) {
00086 DomainType *argX = typeX->getArgType(i);
00087 DomainType *argY = typeY->getArgType(i);
00088 if (!compareTypesUsingRewrites(rewrites, argX, argY))
00089 return false;
00090 }
00091
00092 return true;
00093 }