00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "TypeTest.hpp"
00035
00036 #include <iostream>
00037 #include <string>
00038 #include <sstream>
00039 #include "../Type.hpp"
00040 #include "../BasicType.hpp"
00041 #include "../PointerType.hpp"
00042 #include "TestUtil.hpp"
00043
00044
00045 CPPUNIT_TEST_SUITE_REGISTRATION(TypeTest);
00046
00047 using namespace cfront;
00048
00049 void
00050 TypeTest::testIsCompatibleType()
00051 {
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 }
00069
00070 void
00071 TypeTest::testSizeofType()
00072 {
00073 TargetInfo* targetInfo = makeDefaultTargetInfo();
00074 {
00075
00076 FunctionType ft1(new BasicType(BasicType::SINT));
00077 ft1.addParameterType(new BasicType(BasicType::CHAR));
00078 CPPUNIT_ASSERT(ft1.getSize(*targetInfo) ==
00079 targetInfo->getSize(TargetInfo::POINTER));
00080 }
00081 {
00082
00083
00084
00085
00086
00087 UnionDefinition ud1("");
00088 ud1.addField(new BasicType(BasicType::DOUBLE), 0, "d");
00089 ud1.addField(new BasicType(BasicType::SINT), 0, "i");
00090 ud1.addField(new BasicType(BasicType::CHAR), 0, "c");
00091 CPPUNIT_ASSERT(ud1.getSize(*targetInfo) ==
00092 targetInfo->getSize(TargetInfo::DOUBLE));
00093 }
00094 {
00095
00096
00097
00098
00099
00100 StructDefinition sd1("");
00101 sd1.addField(new BasicType(BasicType::CHAR), 0, "c1");
00102 sd1.addField(new BasicType(BasicType::DOUBLE), 0, "d");
00103 sd1.addField(new BasicType(BasicType::CHAR), 0, "c2");
00104 CPPUNIT_ASSERT(sd1.getSize(*targetInfo) ==
00105 targetInfo->getSize(TargetInfo::DOUBLE) * 3);
00106 }
00107 {
00108
00109
00110
00111 StructDefinition sd1("");
00112 sd1.addField(new BasicType(BasicType::SINT), 0, "i");
00113 CPPUNIT_ASSERT(sd1.getSize(*targetInfo) ==
00114 targetInfo->getSize(TargetInfo::INT));
00115 }
00116 {
00117
00118
00119
00120
00121 StructDefinition sd1("");
00122 sd1.addField(new BasicType(BasicType::CHAR), 0, "c1");
00123 sd1.addField(new BasicType(BasicType::CHAR), 0, "c2");
00124 CPPUNIT_ASSERT(sd1.getSize(*targetInfo) ==
00125 targetInfo->getSize(TargetInfo::CHAR) * 2);
00126 }
00127 {
00128
00129
00130
00131
00132 StructDefinition sd1("");
00133 sd1.addField(new BasicType(BasicType::DOUBLE), 0, "d");
00134 ConstantValue alen = 3;
00135 ArrayType at1(new BasicType(BasicType::SINT), alen, 0);
00136 sd1.addField(&at1, 0, "a");
00137 CPPUNIT_ASSERT(sd1.getSize(*targetInfo) ==
00138 targetInfo->getSize(TargetInfo::DOUBLE) * 3);
00139 }
00140 }