Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 1 | //===--- StmtSerialization.cpp - Serialization of Statements --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Ted Kremenek and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the type-specific methods for serializing statements |
| 11 | // and expressions. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 15 | #include "clang/AST/Expr.h" |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 16 | #include "llvm/Bitcode/Serialize.h" |
| 17 | #include "llvm/Bitcode/Deserialize.h" |
| 18 | |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 19 | using namespace clang; |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 20 | using llvm::Serializer; |
| 21 | using llvm::Deserializer; |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 22 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 23 | void Stmt::Emit(Serializer& S) const { |
Ted Kremenek | b9b543d | 2007-11-07 22:32:23 +0000 | [diff] [blame] | 24 | S.FlushRecord(); |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 25 | S.EmitInt(getStmtClass()); |
| 26 | directEmit(S); |
Ted Kremenek | 8c9833b | 2007-11-07 22:39:17 +0000 | [diff] [blame] | 27 | S.FlushRecord(); |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 28 | } |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 29 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 30 | Stmt* Stmt::Materialize(Deserializer& D) { |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 31 | StmtClass SC = static_cast<StmtClass>(D.ReadInt()); |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 32 | |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 33 | switch (SC) { |
| 34 | default: |
| 35 | assert (false && "Not implemented."); |
| 36 | return NULL; |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 37 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 38 | case ArraySubscriptExprClass: |
| 39 | return ArraySubscriptExpr::directMaterialize(D); |
| 40 | |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 41 | case BinaryOperatorClass: |
| 42 | return BinaryOperator::directMaterialize(D); |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 43 | |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 44 | case BreakStmtClass: |
| 45 | return BreakStmt::directMaterialize(D); |
Ted Kremenek | 7a87333 | 2007-11-07 23:32:20 +0000 | [diff] [blame] | 46 | |
| 47 | case CallExprClass: |
| 48 | return CallExpr::directMaterialize(D); |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 49 | |
| 50 | case CaseStmtClass: |
| 51 | return CaseStmt::directMaterialize(D); |
Ted Kremenek | 705cb5d | 2007-11-07 22:42:34 +0000 | [diff] [blame] | 52 | |
| 53 | case CastExprClass: |
| 54 | return CastExpr::directMaterialize(D); |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 55 | |
Ted Kremenek | 42f440c | 2007-11-07 17:15:49 +0000 | [diff] [blame] | 56 | case CharacterLiteralClass: |
| 57 | return CharacterLiteral::directMaterialize(D); |
| 58 | |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 59 | case CompoundStmtClass: |
| 60 | return CompoundStmt::directMaterialize(D); |
| 61 | |
Ted Kremenek | 6c4dba7 | 2007-11-07 17:05:07 +0000 | [diff] [blame] | 62 | case ContinueStmtClass: |
| 63 | return ContinueStmt::directMaterialize(D); |
| 64 | |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 65 | case DeclRefExprClass: |
| 66 | return DeclRefExpr::directMaterialize(D); |
| 67 | |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 68 | case DeclStmtClass: |
| 69 | return DeclStmt::directMaterialize(D); |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 70 | |
| 71 | case DefaultStmtClass: |
| 72 | return DefaultStmt::directMaterialize(D); |
Ted Kremenek | ab97f4d | 2007-11-07 07:53:55 +0000 | [diff] [blame] | 73 | |
| 74 | case DoStmtClass: |
| 75 | return DoStmt::directMaterialize(D); |
Ted Kremenek | 18abf6b | 2007-11-07 18:45:55 +0000 | [diff] [blame] | 76 | |
| 77 | case FloatingLiteralClass: |
| 78 | return FloatingLiteral::directMaterialize(D); |
Ted Kremenek | f34da90 | 2007-11-07 08:02:55 +0000 | [diff] [blame] | 79 | |
| 80 | case ForStmtClass: |
| 81 | return ForStmt::directMaterialize(D); |
Ted Kremenek | affd8be | 2007-11-07 08:07:46 +0000 | [diff] [blame] | 82 | |
| 83 | case GotoStmtClass: |
| 84 | return GotoStmt::directMaterialize(D); |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 85 | |
Ted Kremenek | ca22d35 | 2007-11-07 07:19:30 +0000 | [diff] [blame] | 86 | case IfStmtClass: |
| 87 | return IfStmt::directMaterialize(D); |
Ted Kremenek | 105f21a | 2007-11-07 18:53:02 +0000 | [diff] [blame] | 88 | |
| 89 | case ImaginaryLiteralClass: |
| 90 | return ImaginaryLiteral::directMaterialize(D); |
Ted Kremenek | ca22d35 | 2007-11-07 07:19:30 +0000 | [diff] [blame] | 91 | |
Ted Kremenek | 8c9833b | 2007-11-07 22:39:17 +0000 | [diff] [blame] | 92 | case ImplicitCastExprClass: |
| 93 | return ImplicitCastExpr::directMaterialize(D); |
| 94 | |
Ted Kremenek | e7d27d5 | 2007-11-07 17:02:32 +0000 | [diff] [blame] | 95 | case IndirectGotoStmtClass: |
| 96 | return IndirectGotoStmt::directMaterialize(D); |
| 97 | |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 98 | case IntegerLiteralClass: |
Ted Kremenek | 25aaa26 | 2007-11-07 00:40:53 +0000 | [diff] [blame] | 99 | return IntegerLiteral::directMaterialize(D); |
| 100 | |
Ted Kremenek | 56a74bb | 2007-11-07 00:48:04 +0000 | [diff] [blame] | 101 | case LabelStmtClass: |
| 102 | return LabelStmt::directMaterialize(D); |
| 103 | |
Ted Kremenek | 25aaa26 | 2007-11-07 00:40:53 +0000 | [diff] [blame] | 104 | case NullStmtClass: |
| 105 | return NullStmt::directMaterialize(D); |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 106 | |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 107 | case ParenExprClass: |
| 108 | return ParenExpr::directMaterialize(D); |
| 109 | |
Ted Kremenek | 539a418 | 2007-11-07 17:11:58 +0000 | [diff] [blame] | 110 | case PreDefinedExprClass: |
| 111 | return PreDefinedExpr::directMaterialize(D); |
| 112 | |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 113 | case ReturnStmtClass: |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 114 | return ReturnStmt::directMaterialize(D); |
Ted Kremenek | efa540d | 2007-11-07 19:08:19 +0000 | [diff] [blame] | 115 | |
| 116 | case StringLiteralClass: |
| 117 | return StringLiteral::directMaterialize(D); |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 118 | |
| 119 | case SwitchStmtClass: |
| 120 | return SwitchStmt::directMaterialize(D); |
Ted Kremenek | 55e559a | 2007-11-07 07:50:10 +0000 | [diff] [blame] | 121 | |
Ted Kremenek | e21b584 | 2007-11-08 00:26:24 +0000 | [diff] [blame] | 122 | case UnaryOperatorClass: |
| 123 | return UnaryOperator::directMaterialize(D); |
| 124 | |
Ted Kremenek | 55e559a | 2007-11-07 07:50:10 +0000 | [diff] [blame] | 125 | case WhileStmtClass: |
| 126 | return WhileStmt::directMaterialize(D); |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 127 | } |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 130 | void ArraySubscriptExpr::directEmit(Serializer& S) const { |
| 131 | S.Emit(getType()); |
| 132 | S.Emit(RBracketLoc); |
| 133 | S.BatchEmitOwnedPtrs(getLHS(),getRHS()); |
| 134 | } |
| 135 | |
| 136 | ArraySubscriptExpr* ArraySubscriptExpr::directMaterialize(Deserializer& D) { |
| 137 | QualType t = QualType::ReadVal(D); |
| 138 | SourceLocation L = SourceLocation::ReadVal(D); |
| 139 | Expr *LHS, *RHS; |
| 140 | D.BatchReadOwnedPtrs(LHS,RHS); |
| 141 | return new ArraySubscriptExpr(LHS,RHS,t,L); |
| 142 | } |
| 143 | |
| 144 | void BinaryOperator::directEmit(Serializer& S) const { |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 145 | S.EmitInt(Opc); |
| 146 | S.Emit(OpLoc);; |
| 147 | S.Emit(getType()); |
Ted Kremenek | b9b543d | 2007-11-07 22:32:23 +0000 | [diff] [blame] | 148 | S.BatchEmitOwnedPtrs(getLHS(),getRHS()); |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 151 | BinaryOperator* BinaryOperator::directMaterialize(Deserializer& D) { |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 152 | Opcode Opc = static_cast<Opcode>(D.ReadInt()); |
| 153 | SourceLocation OpLoc = SourceLocation::ReadVal(D); |
| 154 | QualType Result = QualType::ReadVal(D); |
Ted Kremenek | b9b543d | 2007-11-07 22:32:23 +0000 | [diff] [blame] | 155 | Expr *LHS, *RHS; |
| 156 | D.BatchReadOwnedPtrs(LHS,RHS); |
| 157 | |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 158 | return new BinaryOperator(LHS,RHS,Opc,Result,OpLoc); |
| 159 | } |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 160 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 161 | void BreakStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 162 | S.Emit(BreakLoc); |
| 163 | } |
| 164 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 165 | BreakStmt* BreakStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 166 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 167 | return new BreakStmt(Loc); |
| 168 | } |
Ted Kremenek | 7a87333 | 2007-11-07 23:32:20 +0000 | [diff] [blame] | 169 | |
| 170 | void CallExpr::directEmit(Serializer& S) const { |
| 171 | S.Emit(getType()); |
| 172 | S.Emit(RParenLoc); |
| 173 | S.EmitInt(NumArgs); |
| 174 | S.BatchEmitOwnedPtrs(NumArgs+1,SubExprs); |
| 175 | } |
| 176 | |
| 177 | CallExpr* CallExpr::directMaterialize(Deserializer& D) { |
| 178 | QualType t = QualType::ReadVal(D); |
| 179 | SourceLocation L = SourceLocation::ReadVal(D); |
| 180 | unsigned NumArgs = D.ReadInt(); |
| 181 | Expr** SubExprs = new Expr*[NumArgs+1]; |
| 182 | D.BatchReadOwnedPtrs(NumArgs+1,SubExprs); |
| 183 | |
| 184 | return new CallExpr(SubExprs,NumArgs,t,L); |
| 185 | } |
| 186 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 187 | void CaseStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 188 | S.Emit(CaseLoc); |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 189 | S.EmitPtr(getNextSwitchCase()); |
Ted Kremenek | b9b543d | 2007-11-07 22:32:23 +0000 | [diff] [blame] | 190 | S.BatchEmitOwnedPtrs(getLHS(),getRHS(),getSubStmt()); |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 193 | CaseStmt* CaseStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 194 | SourceLocation CaseLoc = SourceLocation::ReadVal(D); |
Ted Kremenek | b9b543d | 2007-11-07 22:32:23 +0000 | [diff] [blame] | 195 | Expr *LHS, *RHS; |
| 196 | Stmt* SubStmt; |
| 197 | D.BatchReadOwnedPtrs(LHS,RHS,SubStmt); |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 198 | |
| 199 | CaseStmt* stmt = new CaseStmt(LHS,RHS,SubStmt,CaseLoc); |
Ted Kremenek | b9b543d | 2007-11-07 22:32:23 +0000 | [diff] [blame] | 200 | stmt->setNextSwitchCase(D.ReadPtr<SwitchCase>()); |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 201 | return stmt; |
| 202 | } |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 203 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 204 | void CastExpr::directEmit(Serializer& S) const { |
Ted Kremenek | 705cb5d | 2007-11-07 22:42:34 +0000 | [diff] [blame] | 205 | S.Emit(getType()); |
| 206 | S.Emit(Loc); |
| 207 | S.EmitOwnedPtr(Op); |
| 208 | } |
| 209 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 210 | CastExpr* CastExpr::directMaterialize(Deserializer& D) { |
Ted Kremenek | 705cb5d | 2007-11-07 22:42:34 +0000 | [diff] [blame] | 211 | QualType t = QualType::ReadVal(D); |
| 212 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 213 | Expr* Op = D.ReadOwnedPtr<Expr>(); |
| 214 | return new CastExpr(t,Op,Loc); |
| 215 | } |
| 216 | |
| 217 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 218 | void CharacterLiteral::directEmit(Serializer& S) const { |
Ted Kremenek | 42f440c | 2007-11-07 17:15:49 +0000 | [diff] [blame] | 219 | S.Emit(Value); |
| 220 | S.Emit(Loc); |
| 221 | S.Emit(getType()); |
| 222 | } |
| 223 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 224 | CharacterLiteral* CharacterLiteral::directMaterialize(Deserializer& D) { |
Ted Kremenek | 42f440c | 2007-11-07 17:15:49 +0000 | [diff] [blame] | 225 | unsigned value = D.ReadInt(); |
| 226 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 227 | QualType T = QualType::ReadVal(D); |
| 228 | return new CharacterLiteral(value,T,Loc); |
| 229 | } |
| 230 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 231 | void CompoundStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 232 | S.Emit(LBracLoc); |
| 233 | S.Emit(RBracLoc); |
| 234 | S.Emit(Body.size()); |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 235 | |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 236 | for (const_body_iterator I=body_begin(), E=body_end(); I!=E; ++I) |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 237 | S.EmitOwnedPtr(*I); |
| 238 | } |
| 239 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 240 | CompoundStmt* CompoundStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 241 | SourceLocation LB = SourceLocation::ReadVal(D); |
| 242 | SourceLocation RB = SourceLocation::ReadVal(D); |
| 243 | unsigned size = D.ReadInt(); |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 244 | |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 245 | CompoundStmt* stmt = new CompoundStmt(NULL,0,LB,RB); |
| 246 | |
| 247 | stmt->Body.reserve(size); |
| 248 | |
| 249 | for (unsigned i = 0; i < size; ++i) |
| 250 | stmt->Body.push_back(D.ReadOwnedPtr<Stmt>()); |
| 251 | |
| 252 | return stmt; |
Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame] | 253 | } |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 254 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 255 | void ContinueStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 6c4dba7 | 2007-11-07 17:05:07 +0000 | [diff] [blame] | 256 | S.Emit(ContinueLoc); |
| 257 | } |
| 258 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 259 | ContinueStmt* ContinueStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 6c4dba7 | 2007-11-07 17:05:07 +0000 | [diff] [blame] | 260 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 261 | return new ContinueStmt(Loc); |
| 262 | } |
| 263 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 264 | void DeclStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 265 | // FIXME: special handling for struct decls. |
| 266 | S.EmitOwnedPtr(getDecl()); |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 269 | void DeclRefExpr::directEmit(Serializer& S) const { |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 270 | S.Emit(Loc); |
| 271 | S.Emit(getType()); |
| 272 | S.EmitPtr(getDecl()); |
| 273 | } |
| 274 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 275 | DeclRefExpr* DeclRefExpr::directMaterialize(Deserializer& D) { |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 276 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 277 | QualType T = QualType::ReadVal(D); |
| 278 | DeclRefExpr* dr = new DeclRefExpr(NULL,T,Loc); |
| 279 | D.ReadPtr(dr->D,false); |
| 280 | return dr; |
| 281 | } |
| 282 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 283 | DeclStmt* DeclStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 284 | ScopedDecl* decl = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>()); |
| 285 | return new DeclStmt(decl); |
| 286 | } |
| 287 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 288 | void DefaultStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 289 | S.Emit(DefaultLoc); |
| 290 | S.EmitOwnedPtr(getSubStmt()); |
| 291 | S.EmitPtr(getNextSwitchCase()); |
| 292 | } |
| 293 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 294 | DefaultStmt* DefaultStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 295 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 296 | Stmt* SubStmt = D.ReadOwnedPtr<Stmt>(); |
| 297 | |
| 298 | DefaultStmt* stmt = new DefaultStmt(Loc,SubStmt); |
| 299 | stmt->setNextSwitchCase(D.ReadPtr<SwitchCase>()); |
| 300 | |
| 301 | return stmt; |
| 302 | } |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 303 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 304 | void DoStmt::directEmit(Serializer& S) const { |
Ted Kremenek | ab97f4d | 2007-11-07 07:53:55 +0000 | [diff] [blame] | 305 | S.Emit(DoLoc); |
| 306 | S.EmitOwnedPtr(getCond()); |
| 307 | S.EmitOwnedPtr(getBody()); |
| 308 | } |
| 309 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 310 | DoStmt* DoStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | ab97f4d | 2007-11-07 07:53:55 +0000 | [diff] [blame] | 311 | SourceLocation DoLoc = SourceLocation::ReadVal(D); |
| 312 | Expr* Cond = D.ReadOwnedPtr<Expr>(); |
| 313 | Stmt* Body = D.ReadOwnedPtr<Stmt>(); |
| 314 | return new DoStmt(Body,Cond,DoLoc); |
| 315 | } |
| 316 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 317 | void FloatingLiteral::directEmit(Serializer& S) const { |
Ted Kremenek | 18abf6b | 2007-11-07 18:45:55 +0000 | [diff] [blame] | 318 | S.Emit(Loc); |
| 319 | S.Emit(getType()); |
| 320 | S.Emit(Value); |
| 321 | } |
| 322 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 323 | FloatingLiteral* FloatingLiteral::directMaterialize(Deserializer& D) { |
Ted Kremenek | 18abf6b | 2007-11-07 18:45:55 +0000 | [diff] [blame] | 324 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 325 | QualType t = QualType::ReadVal(D); |
| 326 | llvm::APFloat Val = llvm::APFloat::ReadVal(D); |
| 327 | FloatingLiteral* expr = new FloatingLiteral(Val,t,Loc); |
| 328 | return expr; |
| 329 | } |
| 330 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 331 | void ForStmt::directEmit(Serializer& S) const { |
Ted Kremenek | f34da90 | 2007-11-07 08:02:55 +0000 | [diff] [blame] | 332 | S.Emit(ForLoc); |
| 333 | S.EmitOwnedPtr(getInit()); |
| 334 | S.EmitOwnedPtr(getCond()); |
| 335 | S.EmitOwnedPtr(getInc()); |
| 336 | S.EmitOwnedPtr(getBody()); |
| 337 | } |
| 338 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 339 | ForStmt* ForStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | f34da90 | 2007-11-07 08:02:55 +0000 | [diff] [blame] | 340 | SourceLocation ForLoc = SourceLocation::ReadVal(D); |
| 341 | Stmt* Init = D.ReadOwnedPtr<Stmt>(); |
| 342 | Expr* Cond = D.ReadOwnedPtr<Expr>(); |
| 343 | Expr* Inc = D.ReadOwnedPtr<Expr>(); |
| 344 | Stmt* Body = D.ReadOwnedPtr<Stmt>(); |
| 345 | return new ForStmt(Init,Cond,Inc,Body,ForLoc); |
| 346 | } |
| 347 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 348 | void GotoStmt::directEmit(Serializer& S) const { |
Ted Kremenek | affd8be | 2007-11-07 08:07:46 +0000 | [diff] [blame] | 349 | S.Emit(GotoLoc); |
| 350 | S.Emit(LabelLoc); |
| 351 | S.EmitPtr(Label); |
| 352 | } |
| 353 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 354 | GotoStmt* GotoStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | affd8be | 2007-11-07 08:07:46 +0000 | [diff] [blame] | 355 | SourceLocation GotoLoc = SourceLocation::ReadVal(D); |
| 356 | SourceLocation LabelLoc = SourceLocation::ReadVal(D); |
| 357 | GotoStmt* stmt = new GotoStmt(NULL,GotoLoc,LabelLoc); |
| 358 | D.ReadPtr(stmt->Label); // This pointer may be backpatched later. |
| 359 | return stmt; |
| 360 | } |
| 361 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 362 | void IfStmt::directEmit(Serializer& S) const { |
Ted Kremenek | ca22d35 | 2007-11-07 07:19:30 +0000 | [diff] [blame] | 363 | S.Emit(IfLoc); |
| 364 | S.EmitOwnedPtr(getCond()); |
| 365 | S.EmitOwnedPtr(getThen()); |
| 366 | S.EmitOwnedPtr(getElse()); |
| 367 | } |
| 368 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 369 | IfStmt* IfStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | ca22d35 | 2007-11-07 07:19:30 +0000 | [diff] [blame] | 370 | SourceLocation L = SourceLocation::ReadVal(D); |
| 371 | Expr* Cond = D.ReadOwnedPtr<Expr>(); |
| 372 | Stmt* Then = D.ReadOwnedPtr<Stmt>(); |
| 373 | Stmt* Else = D.ReadOwnedPtr<Stmt>(); |
| 374 | return new IfStmt(L,Cond,Then,Else); |
| 375 | } |
| 376 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 377 | void ImaginaryLiteral::directEmit(Serializer& S) const { |
Ted Kremenek | 105f21a | 2007-11-07 18:53:02 +0000 | [diff] [blame] | 378 | S.Emit(getType()); |
| 379 | S.EmitOwnedPtr(Val); |
| 380 | } |
| 381 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 382 | ImaginaryLiteral* ImaginaryLiteral::directMaterialize(Deserializer& D) { |
Ted Kremenek | 105f21a | 2007-11-07 18:53:02 +0000 | [diff] [blame] | 383 | QualType t = QualType::ReadVal(D); |
| 384 | Expr* expr = D.ReadOwnedPtr<Expr>(); |
| 385 | assert (isa<FloatingLiteral>(expr) || isa<IntegerLiteral>(expr)); |
| 386 | return new ImaginaryLiteral(expr,t); |
| 387 | } |
| 388 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 389 | void ImplicitCastExpr::directEmit(Serializer& S) const { |
Ted Kremenek | 8c9833b | 2007-11-07 22:39:17 +0000 | [diff] [blame] | 390 | S.Emit(getType()); |
| 391 | S.EmitOwnedPtr(Op); |
| 392 | } |
| 393 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 394 | ImplicitCastExpr* ImplicitCastExpr::directMaterialize(Deserializer& D) { |
Ted Kremenek | 8c9833b | 2007-11-07 22:39:17 +0000 | [diff] [blame] | 395 | QualType t = QualType::ReadVal(D); |
| 396 | Expr* Op = D.ReadOwnedPtr<Expr>(); |
| 397 | return new ImplicitCastExpr(t,Op); |
| 398 | } |
| 399 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 400 | void IndirectGotoStmt::directEmit(Serializer& S) const { |
Ted Kremenek | e7d27d5 | 2007-11-07 17:02:32 +0000 | [diff] [blame] | 401 | S.EmitPtr(Target); |
| 402 | } |
| 403 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 404 | IndirectGotoStmt* IndirectGotoStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | e7d27d5 | 2007-11-07 17:02:32 +0000 | [diff] [blame] | 405 | IndirectGotoStmt* stmt = new IndirectGotoStmt(NULL); |
| 406 | D.ReadPtr(stmt->Target); // The target may be backpatched. |
| 407 | return stmt; |
| 408 | } |
| 409 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 410 | void IntegerLiteral::directEmit(Serializer& S) const { |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 411 | S.Emit(Loc); |
| 412 | S.Emit(getType()); |
| 413 | S.Emit(getValue()); |
| 414 | } |
| 415 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 416 | IntegerLiteral* IntegerLiteral::directMaterialize(Deserializer& D) { |
Ted Kremenek | 4728110 | 2007-11-07 00:17:35 +0000 | [diff] [blame] | 417 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 418 | QualType T = QualType::ReadVal(D); |
| 419 | |
| 420 | // Create a dummy APInt because it is more efficient to deserialize |
| 421 | // it in place with the deserialized IntegerLiteral. (fewer copies) |
| 422 | llvm::APInt temp; |
| 423 | IntegerLiteral* expr = new IntegerLiteral(temp,T,Loc); |
| 424 | D.Read(expr->Value); |
| 425 | |
| 426 | return expr; |
| 427 | } |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 428 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 429 | void LabelStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 56a74bb | 2007-11-07 00:48:04 +0000 | [diff] [blame] | 430 | S.EmitPtr(Label); |
| 431 | S.Emit(IdentLoc); |
| 432 | S.EmitOwnedPtr(SubStmt); |
| 433 | } |
| 434 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 435 | LabelStmt* LabelStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 56a74bb | 2007-11-07 00:48:04 +0000 | [diff] [blame] | 436 | IdentifierInfo* Label = D.ReadPtr<IdentifierInfo>(); |
| 437 | SourceLocation IdentLoc = SourceLocation::ReadVal(D); |
| 438 | Stmt* SubStmt = D.ReadOwnedPtr<Stmt>(); |
| 439 | return new LabelStmt(IdentLoc,Label,SubStmt); |
| 440 | } |
| 441 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 442 | void NullStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 25aaa26 | 2007-11-07 00:40:53 +0000 | [diff] [blame] | 443 | S.Emit(SemiLoc); |
| 444 | } |
| 445 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 446 | NullStmt* NullStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 25aaa26 | 2007-11-07 00:40:53 +0000 | [diff] [blame] | 447 | SourceLocation SemiLoc = SourceLocation::ReadVal(D); |
| 448 | return new NullStmt(SemiLoc); |
| 449 | } |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 450 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 451 | void ParenExpr::directEmit(Serializer& S) const { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 452 | S.Emit(L); |
| 453 | S.Emit(R); |
| 454 | S.EmitOwnedPtr(Val); |
| 455 | } |
| 456 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 457 | ParenExpr* ParenExpr::directMaterialize(Deserializer& D) { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 458 | SourceLocation L = SourceLocation::ReadVal(D); |
| 459 | SourceLocation R = SourceLocation::ReadVal(D); |
| 460 | Expr* val = D.ReadOwnedPtr<Expr>(); |
| 461 | return new ParenExpr(L,R,val); |
Ted Kremenek | 539a418 | 2007-11-07 17:11:58 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 464 | void PreDefinedExpr::directEmit(Serializer& S) const { |
Ted Kremenek | 539a418 | 2007-11-07 17:11:58 +0000 | [diff] [blame] | 465 | S.Emit(Loc); |
| 466 | S.EmitInt(getIdentType()); |
| 467 | S.Emit(getType()); |
| 468 | } |
| 469 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 470 | PreDefinedExpr* PreDefinedExpr::directMaterialize(Deserializer& D) { |
Ted Kremenek | 539a418 | 2007-11-07 17:11:58 +0000 | [diff] [blame] | 471 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 472 | IdentType it = static_cast<IdentType>(D.ReadInt()); |
| 473 | QualType Q = QualType::ReadVal(D); |
| 474 | return new PreDefinedExpr(Loc,Q,it); |
| 475 | } |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 476 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 477 | void ReturnStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 478 | S.Emit(RetLoc); |
| 479 | S.EmitOwnedPtr(RetExpr); |
| 480 | } |
| 481 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 482 | ReturnStmt* ReturnStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 2bd6e65 | 2007-11-07 00:37:40 +0000 | [diff] [blame] | 483 | SourceLocation RetLoc = SourceLocation::ReadVal(D); |
| 484 | Expr* RetExpr = D.ReadOwnedPtr<Expr>(); |
| 485 | return new ReturnStmt(RetLoc,RetExpr); |
| 486 | } |
| 487 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 488 | void StringLiteral::directEmit(Serializer& S) const { |
Ted Kremenek | efa540d | 2007-11-07 19:08:19 +0000 | [diff] [blame] | 489 | S.Emit(getType()); |
| 490 | S.Emit(firstTokLoc); |
| 491 | S.Emit(lastTokLoc); |
| 492 | S.EmitBool(isWide()); |
| 493 | S.Emit(getByteLength()); |
| 494 | |
| 495 | for (unsigned i = 0 ; i < ByteLength; ++i) |
| 496 | S.EmitInt(StrData[i]); |
| 497 | } |
| 498 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 499 | StringLiteral* StringLiteral::directMaterialize(Deserializer& D) { |
Ted Kremenek | efa540d | 2007-11-07 19:08:19 +0000 | [diff] [blame] | 500 | QualType t = QualType::ReadVal(D); |
| 501 | SourceLocation firstTokLoc = SourceLocation::ReadVal(D); |
| 502 | SourceLocation lastTokLoc = SourceLocation::ReadVal(D); |
| 503 | bool isWide = D.ReadBool(); |
| 504 | unsigned ByteLength = D.ReadInt(); |
| 505 | |
| 506 | StringLiteral* sl = new StringLiteral(NULL,0,isWide,t,firstTokLoc,lastTokLoc); |
| 507 | |
| 508 | char* StrData = new char[ByteLength]; |
| 509 | for (unsigned i = 0; i < ByteLength; ++i) |
| 510 | StrData[i] = (char) D.ReadInt(); |
| 511 | |
| 512 | sl->ByteLength = ByteLength; |
| 513 | sl->StrData = StrData; |
| 514 | |
| 515 | return sl; |
| 516 | } |
| 517 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 518 | void SwitchStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 519 | S.Emit(SwitchLoc); |
| 520 | S.EmitOwnedPtr(getCond()); |
| 521 | S.EmitOwnedPtr(getBody()); |
| 522 | S.EmitPtr(FirstCase); |
| 523 | } |
| 524 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 525 | SwitchStmt* SwitchStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 249d7cd | 2007-11-07 05:25:31 +0000 | [diff] [blame] | 526 | SourceLocation Loc = SourceLocation::ReadVal(D); |
| 527 | Stmt* Cond = D.ReadOwnedPtr<Stmt>(); |
| 528 | Stmt* Body = D.ReadOwnedPtr<Stmt>(); |
| 529 | SwitchCase* FirstCase = cast<SwitchCase>(D.ReadPtr<Stmt>()); |
| 530 | |
| 531 | SwitchStmt* stmt = new SwitchStmt(cast<Expr>(Cond)); |
| 532 | stmt->setBody(Body,Loc); |
| 533 | stmt->FirstCase = FirstCase; |
| 534 | |
| 535 | return stmt; |
| 536 | } |
Ted Kremenek | 55e559a | 2007-11-07 07:50:10 +0000 | [diff] [blame] | 537 | |
Ted Kremenek | e21b584 | 2007-11-08 00:26:24 +0000 | [diff] [blame] | 538 | void UnaryOperator::directEmit(Serializer& S) const { |
| 539 | S.Emit(getType()); |
| 540 | S.Emit(Loc); |
| 541 | S.EmitInt(Opc); |
| 542 | S.EmitOwnedPtr(Val); |
| 543 | } |
| 544 | |
| 545 | UnaryOperator* UnaryOperator::directMaterialize(Deserializer& D) { |
| 546 | QualType t = QualType::ReadVal(D); |
| 547 | SourceLocation L = SourceLocation::ReadVal(D); |
| 548 | Opcode Opc = static_cast<Opcode>(D.ReadInt()); |
| 549 | Expr* Val = D.ReadOwnedPtr<Expr>(); |
| 550 | return new UnaryOperator(Val,Opc,t,L); |
| 551 | } |
| 552 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 553 | void WhileStmt::directEmit(Serializer& S) const { |
Ted Kremenek | 55e559a | 2007-11-07 07:50:10 +0000 | [diff] [blame] | 554 | S.Emit(WhileLoc); |
| 555 | S.EmitOwnedPtr(getCond()); |
| 556 | S.EmitOwnedPtr(getBody()); |
| 557 | } |
| 558 | |
Ted Kremenek | d701749 | 2007-11-07 22:53:01 +0000 | [diff] [blame] | 559 | WhileStmt* WhileStmt::directMaterialize(Deserializer& D) { |
Ted Kremenek | 55e559a | 2007-11-07 07:50:10 +0000 | [diff] [blame] | 560 | SourceLocation WhileLoc = SourceLocation::ReadVal(D); |
| 561 | Expr* Cond = D.ReadOwnedPtr<Expr>(); |
| 562 | Stmt* Body = D.ReadOwnedPtr<Stmt>(); |
| 563 | return new WhileStmt(Cond,Body,WhileLoc); |
| 564 | } |