 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
72.4% |
42 / 58 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
82.8% |
48 / 58 |
| |
|
Line Coverage: |
70.8% |
63 / 89 |
| |
 |
|
 |
1 : //===--- APValue.cpp - Union class for APFloat/APSInt/Complex -------------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file implements the APValue class.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #include "clang/AST/APValue.h"
15 : #include "clang/AST/CharUnits.h"
16 : #include "llvm/Support/raw_ostream.h"
17 : using namespace clang;
18 :
19 : namespace {
20 8298: struct LV {
21 : Expr* Base;
22 : CharUnits Offset;
23 : };
24 : }
25 :
26 742: APValue::APValue(Expr* B) : Kind(Uninitialized) {
27 742: MakeLValue(); setLValue(B, CharUnits::Zero());
28 742: }
29 :
30 32068: const APValue &APValue::operator=(const APValue &RHS) {
24624: branch 0 taken
7444: branch 1 taken
31 32068: if (Kind != RHS.Kind) {
32 24624: MakeUninit();
20743: branch 1 taken
3881: branch 2 taken
33 24624: if (RHS.isInt())
34 20743: MakeInt();
459: branch 1 taken
3422: branch 2 taken
35 3881: else if (RHS.isFloat())
36 459: MakeFloat();
13: branch 1 taken
3409: branch 2 taken
37 3422: else if (RHS.isVector())
38 13: MakeVector();
119: branch 1 taken
3290: branch 2 taken
39 3409: else if (RHS.isComplexInt())
40 119: MakeComplexInt();
126: branch 1 taken
3164: branch 2 taken
41 3290: else if (RHS.isComplexFloat())
42 126: MakeComplexFloat();
3164: branch 1 taken
0: branch 2 not taken
43 3164: else if (RHS.isLValue())
44 3164: MakeLValue();
45 : }
25530: branch 1 taken
6538: branch 2 taken
46 32068: if (isInt())
47 25530: setInt(RHS.getInt());
460: branch 1 taken
6078: branch 2 taken
48 6538: else if (isFloat())
49 460: setFloat(RHS.getFloat());
13: branch 1 taken
6065: branch 2 taken
50 6078: else if (isVector())
51 13: setVector(((Vec*)(char*)RHS.Data)->Elts, RHS.getVectorLength());
119: branch 1 taken
5946: branch 2 taken
52 6065: else if (isComplexInt())
53 119: setComplexInt(RHS.getComplexIntReal(), RHS.getComplexIntImag());
126: branch 1 taken
5820: branch 2 taken
54 5946: else if (isComplexFloat())
55 126: setComplexFloat(RHS.getComplexFloatReal(), RHS.getComplexFloatImag());
3166: branch 1 taken
2654: branch 2 taken
56 5820: else if (isLValue())
57 3166: setLValue(RHS.getLValueBase(), RHS.getLValueOffset());
58 32068: return *this;
59 : }
60 :
61 87955: void APValue::MakeUninit() {
45717: branch 0 taken
42238: branch 1 taken
62 87955: if (Kind == Int)
63 45717: ((APSInt*)(char*)Data)->~APSInt();
883: branch 0 taken
41355: branch 1 taken
64 42238: else if (Kind == Float)
65 883: ((APFloat*)(char*)Data)->~APFloat();
24: branch 0 taken
41331: branch 1 taken
66 41355: else if (Kind == Vector)
67 24: ((Vec*)(char*)Data)->~Vec();
173: branch 0 taken
41158: branch 1 taken
68 41331: else if (Kind == ComplexInt)
69 173: ((ComplexAPSInt*)(char*)Data)->~ComplexAPSInt();
186: branch 0 taken
40972: branch 1 taken
70 41158: else if (Kind == ComplexFloat)
71 186: ((ComplexAPFloat*)(char*)Data)->~ComplexAPFloat();
4149: branch 0 taken
36823: branch 1 taken
72 40972: else if (Kind == LValue) {
73 4149: ((LV*)(char*)Data)->~LV();
74 : }
75 87955: Kind = Uninitialized;
76 87955: }
77 :
78 0: void APValue::dump() const {
79 0: print(llvm::errs());
80 0: llvm::errs() << '\n';
81 0: }
82 :
83 0: static double GetApproxValue(const llvm::APFloat &F) {
84 0: llvm::APFloat V = F;
85 : bool ignored;
86 : V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven,
87 0: &ignored);
88 0: return V.convertToDouble();
89 : }
90 :
91 0: void APValue::print(llvm::raw_ostream &OS) const {
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 7 not taken
0: branch 8 not taken
92 0: switch (getKind()) {
93 0: default: assert(0 && "Unknown APValue kind!");
94 : case Uninitialized:
95 0: OS << "Uninitialized";
96 0: return;
97 : case Int:
98 0: OS << "Int: " << getInt();
99 0: return;
100 : case Float:
101 0: OS << "Float: " << GetApproxValue(getFloat());
102 0: return;
103 : case Vector:
104 0: OS << "Vector: " << getVectorElt(0);
0: branch 1 not taken
0: branch 2 not taken
105 0: for (unsigned i = 1; i != getVectorLength(); ++i)
106 0: OS << ", " << getVectorElt(i);
107 0: return;
108 : case ComplexInt:
109 0: OS << "ComplexInt: " << getComplexIntReal() << ", " << getComplexIntImag();
110 0: return;
111 : case ComplexFloat:
112 : OS << "ComplexFloat: " << GetApproxValue(getComplexFloatReal())
113 0: << ", " << GetApproxValue(getComplexFloatImag());
114 : case LValue:
115 0: OS << "LValue: <todo>";
116 0: return;
117 : }
118 : }
119 :
120 4073: Expr* APValue::getLValueBase() const {
4073: branch 1 taken
0: branch 2 not taken
121 4073: assert(isLValue() && "Invalid accessor");
122 4073: return ((const LV*)(const void*)Data)->Base;
123 : }
124 :
125 4019: CharUnits APValue::getLValueOffset() const {
4019: branch 1 taken
0: branch 2 not taken
126 4019: assert(isLValue() && "Invalid accessor");
127 4019: return ((const LV*)(const void*)Data)->Offset;
128 : }
129 :
130 4492: void APValue::setLValue(Expr *B, const CharUnits &O) {
4492: branch 1 taken
0: branch 2 not taken
131 4492: assert(isLValue() && "Invalid accessor");
132 4492: ((LV*)(char*)Data)->Base = B;
133 4492: ((LV*)(char*)Data)->Offset = O;
134 4492: }
135 :
136 4149: void APValue::MakeLValue() {
4149: branch 1 taken
0: branch 2 not taken
137 4149: assert(isUninit() && "Bad state change");
4149: branch 1 taken
0: branch 2 not taken
138 8298: new ((void*)(char*)Data) LV();
139 4149: Kind = LValue;
140 4149: }
141 :
Generated: 2010-02-10 01:31 by zcov