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