1 package polyglot.ext.jl.ast; 2 3 import polyglot.ast.*; 4 import polyglot.ast.Assert; 5 import polyglot.types.Flags; 6 import polyglot.types.Package; 7 import polyglot.types.Type; 8 import polyglot.types.Qualifier; 9 import polyglot.util.*; 10 import java.util.*; 11 12 17 public class NodeFactory_c extends AbstractNodeFactory_c 18 { 19 private final ExtFactory extFactory; 20 private final DelFactory delFactory; 21 public NodeFactory_c() { 22 this(new AbstractExtFactory_c() {}, 25 new AbstractDelFactory_c() {}); 26 } 27 public NodeFactory_c(ExtFactory extFactory) { 28 this(extFactory, 29 new AbstractDelFactory_c() {}); 30 } 31 public NodeFactory_c(ExtFactory extFactory, 32 DelFactory delFactory ) { 33 this.extFactory = extFactory; 34 this.delFactory = delFactory; 35 } 36 37 protected ExtFactory extFactory() { 38 return this.extFactory; 39 } 40 41 protected DelFactory delFactory() { 42 return this.delFactory; 43 } 44 45 48 protected final ExtFactory findExtFactInstance(Class c) { 49 ExtFactory e = extFactory(); 50 while (e != null) { 51 if (c.isInstance(e)) { 52 return e; 54 } 55 e = e.nextExtFactory(); 56 } 57 return null; 58 } 59 60 public AmbPrefix AmbPrefix(Position pos, Prefix prefix, String name) { 61 AmbPrefix n = new AmbPrefix_c(pos, prefix, name); 62 n = (AmbPrefix)n.ext(extFactory.extAmbPrefix()); 63 n = (AmbPrefix)n.del(delFactory.delAmbPrefix()); 64 return n; 65 } 66 67 public AmbReceiver AmbReceiver(Position pos, Prefix prefix, String name) { 68 AmbReceiver n = new AmbReceiver_c(pos, prefix, name); 69 n = (AmbReceiver)n.ext(extFactory.extAmbReceiver()); 70 n = (AmbReceiver)n.del(delFactory.delAmbReceiver()); 71 return n; 72 } 73 74 public AmbQualifierNode AmbQualifierNode(Position pos, QualifierNode qualifier, String name) { 75 AmbQualifierNode n = new AmbQualifierNode_c(pos, qualifier, name); 76 n = (AmbQualifierNode)n.ext(extFactory.extAmbQualifierNode()); 77 n = (AmbQualifierNode)n.del(delFactory.delAmbQualifierNode()); 78 return n; 79 } 80 81 public AmbExpr AmbExpr(Position pos, String name) { 82 AmbExpr n = new AmbExpr_c(pos, name); 83 n = (AmbExpr)n.ext(extFactory.extAmbExpr()); 84 n = (AmbExpr)n.del(delFactory.delAmbExpr()); 85 return n; 86 } 87 88 public AmbTypeNode AmbTypeNode(Position pos, QualifierNode qualifier, String name) { 89 AmbTypeNode n = new AmbTypeNode_c(pos, qualifier, name); 90 n = (AmbTypeNode)n.ext(extFactory.extAmbTypeNode()); 91 n = (AmbTypeNode)n.del(delFactory.delAmbTypeNode()); 92 return n; 93 } 94 95 public ArrayAccess ArrayAccess(Position pos, Expr base, Expr index) { 96 ArrayAccess n = new ArrayAccess_c(pos, base, index); 97 n = (ArrayAccess)n.ext(extFactory.extArrayAccess()); 98 n = (ArrayAccess)n.del(delFactory.delArrayAccess()); 99 return n; 100 } 101 102 public ArrayInit ArrayInit(Position pos, List elements) { 103 ArrayInit n = new ArrayInit_c(pos, elements); 104 n = (ArrayInit)n.ext(extFactory.extArrayInit()); 105 n = (ArrayInit)n.del(delFactory.delArrayInit()); 106 return n; 107 } 108 109 public Assert Assert(Position pos, Expr cond, Expr errorMessage) { 110 Assert n = new Assert_c(pos, cond, errorMessage); 111 n = (Assert)n.ext(extFactory.extAssert()); 112 n = (Assert)n.del(delFactory.delAssert()); 113 return n; 114 } 115 116 public Assign Assign(Position pos, Expr left, Assign.Operator op, Expr right) { 117 if (left instanceof Local) { 118 return LocalAssign(pos, (Local)left, op, right); 119 } 120 else if (left instanceof Field) { 121 return FieldAssign(pos, (Field)left, op, right); 122 } 123 else if (left instanceof ArrayAccess) { 124 return ArrayAccessAssign(pos, (ArrayAccess)left, op, right); 125 } 126 return AmbAssign(pos, left, op, right); 127 } 128 129 public LocalAssign LocalAssign(Position pos, Local left, Assign.Operator op, Expr right) { 130 LocalAssign n = new LocalAssign_c(pos, left, op, right); 131 n = (LocalAssign)n.ext(extFactory.extLocalAssign()); 132 n = (LocalAssign)n.del(delFactory.delLocalAssign()); 133 return n; 134 } 135 public FieldAssign FieldAssign(Position pos, Field left, Assign.Operator op, Expr right) { 136 FieldAssign n = new FieldAssign_c(pos, left, op, right); 137 n = (FieldAssign)n.ext(extFactory.extFieldAssign()); 138 n = (FieldAssign)n.del(delFactory.delFieldAssign()); 139 return n; 140 } 141 public ArrayAccessAssign ArrayAccessAssign(Position pos, ArrayAccess left, Assign.Operator op, Expr right) { 142 ArrayAccessAssign n = new ArrayAccessAssign_c(pos, left, op, right); 143 n = (ArrayAccessAssign)n.ext(extFactory.extArrayAccessAssign()); 144 n = (ArrayAccessAssign)n.del(delFactory.delArrayAccessAssign()); 145 return n; 146 } 147 public AmbAssign AmbAssign(Position pos, Expr left, Assign.Operator op, Expr right) { 148 AmbAssign n = new AmbAssign_c(pos, left, op, right); 149 n = (AmbAssign)n.ext(extFactory.extAmbAssign()); 150 n = (AmbAssign)n.del(delFactory.delAmbAssign()); 151 return n; 152 } 153 154 155 public Binary Binary(Position pos, Expr left, Binary.Operator op, Expr right) { 156 Binary n = new Binary_c(pos, left, op, right); 157 n = (Binary)n.ext(extFactory.extBinary()); 158 n = (Binary)n.del(delFactory.delBinary()); 159 return n; 160 } 161 162 public Block Block(Position pos, List statements) { 163 Block n = new Block_c(pos, statements); 164 n = (Block)n.ext(extFactory.extBlock()); 165 n = (Block)n.del(delFactory.delBlock()); 166 return n; 167 } 168 169 public SwitchBlock SwitchBlock(Position pos, List statements) { 170 SwitchBlock n = new SwitchBlock_c(pos, statements); 171 n = (SwitchBlock)n.ext(extFactory.extSwitchBlock()); 172 n = (SwitchBlock)n.del(delFactory.delSwitchBlock()); 173 return n; 174 } 175 176 public BooleanLit BooleanLit(Position pos, boolean value) { 177 BooleanLit n = new BooleanLit_c(pos, value); 178 n = (BooleanLit)n.ext(extFactory.extBooleanLit()); 179 n = (BooleanLit)n.del(delFactory.delBooleanLit()); 180 return n; 181 } 182 183 public Branch Branch(Position pos, Branch.Kind kind, String label) { 184 Branch n = new Branch_c(pos, kind, label); 185 n = (Branch)n.ext(extFactory.extBranch()); 186 n = (Branch)n.del(delFactory.delBranch()); 187 return n; 188 } 189 190 public Call Call(Position pos, Receiver target, String name, List args) { 191 Call n = new Call_c(pos, target, name, args); 192 n = (Call)n.ext(extFactory.extCall()); 193 n = (Call)n.del(delFactory.delCall()); 194 return n; 195 } 196 197 public Case Case(Position pos, Expr expr) { 198 Case n = new Case_c(pos, expr); 199 n = (Case)n.ext(extFactory.extCase()); 200 n = (Case)n.del(delFactory.delCase()); 201 return n; 202 } 203 204 public Cast Cast(Position pos, TypeNode type, Expr expr) { 205 Cast n = new Cast_c(pos, type, expr); 206 n = (Cast)n.ext(extFactory.extCast()); 207 n = (Cast)n.del(delFactory.delCast()); 208 return n; 209 } 210 211 public Catch Catch(Position pos, Formal formal, Block body) { 212 Catch n = new Catch_c(pos, formal, body); 213 n = (Catch)n.ext(extFactory.extCatch()); 214 n = (Catch)n.del(delFactory.delCatch()); 215 return n; 216 } 217 218 public CharLit CharLit(Position pos, char value) { 219 CharLit n = new CharLit_c(pos, value); 220 n = (CharLit)n.ext(extFactory.extCharLit()); 221 n = (CharLit)n.del(delFactory.delCharLit()); 222 return n; 223 } 224 225 public ClassBody ClassBody(Position pos, List members) { 226 ClassBody n = new ClassBody_c(pos, members); 227 n = (ClassBody)n.ext(extFactory.extClassBody()); 228 n = (ClassBody)n.del(delFactory.delClassBody()); 229 return n; 230 } 231 232 public ClassDecl ClassDecl(Position pos, Flags flags, String name, TypeNode superClass, List interfaces, ClassBody body) { 233 ClassDecl n = new ClassDecl_c(pos, flags, name, superClass, interfaces, body); 234 n = (ClassDecl)n.ext(extFactory.extClassDecl()); 235 n = (ClassDecl)n.del(delFactory.delClassDecl()); 236 return n; 237 } 238 239 public ClassLit ClassLit(Position pos, TypeNode typeNode) { 240 ClassLit n = new ClassLit_c(pos, typeNode); 241 n = (ClassLit)n.ext(extFactory.extClassLit()); 242 n = (ClassLit)n.del(delFactory.delClassLit()); 243 return n; 244 } 245 246 public Conditional Conditional(Position pos, Expr cond, Expr consequent, Expr alternative) { 247 Conditional n = new Conditional_c(pos, cond, consequent, alternative); 248 n = (Conditional)n.ext(extFactory.extConditional()); 249 n = (Conditional)n.del(delFactory.delConditional()); 250 return n; 251 } 252 253 public ConstructorCall ConstructorCall(Position pos, ConstructorCall.Kind kind, Expr outer, List args) { 254 ConstructorCall n = new ConstructorCall_c(pos, kind, outer, args); 255 n = (ConstructorCall)n.ext(extFactory.extConstructorCall()); 256 n = (ConstructorCall)n.del(delFactory.delConstructorCall()); 257 return n; 258 } 259 260 public ConstructorDecl ConstructorDecl(Position pos, Flags flags, String name, List formals, List throwTypes, Block body) { 261 ConstructorDecl n = new ConstructorDecl_c(pos, flags, name, formals, throwTypes, body); 262 n = (ConstructorDecl)n.ext(extFactory.extConstructorDecl()); 263 n = (ConstructorDecl)n.del(delFactory.delConstructorDecl()); 264 return n; 265 } 266 267 public FieldDecl FieldDecl(Position pos, Flags flags, TypeNode type, String name, Expr init) { 268 FieldDecl n = new FieldDecl_c(pos, flags, type, name, init); 269 n = (FieldDecl)n.ext(extFactory.extFieldDecl()); 270 n = (FieldDecl)n.del(delFactory.delFieldDecl()); 271 return n; 272 } 273 274 public Do Do(Position pos, Stmt body, Expr cond) { 275 Do n = new Do_c(pos, body, cond); 276 n = (Do)n.ext(extFactory.extDo()); 277 n = (Do)n.del(delFactory.delDo()); 278 return n; 279 } 280 281 public Empty Empty(Position pos) { 282 Empty n = new Empty_c(pos); 283 n = (Empty)n.ext(extFactory.extEmpty()); 284 n = (Empty)n.del(delFactory.delEmpty()); 285 return n; 286 } 287 288 public Eval Eval(Position pos, Expr expr) { 289 Eval n = new Eval_c(pos, expr); 290 n = (Eval)n.ext(extFactory.extEval()); 291 n = (Eval)n.del(delFactory.delEval()); 292 return n; 293 } 294 295 public Field Field(Position pos, Receiver target, String name) { 296 Field n = new Field_c(pos, target, name); 297 n = (Field)n.ext(extFactory.extField()); 298 n = (Field)n.del(delFactory.delField()); 299 return n; 300 } 301 302 public FloatLit FloatLit(Position pos, FloatLit.Kind kind, double value) { 303 FloatLit n = new FloatLit_c(pos, kind, value); 304 n = (FloatLit)n.ext(extFactory.extFloatLit()); 305 n = (FloatLit)n.del(delFactory.delFloatLit()); 306 return n; 307 } 308 309 public For For(Position pos, List inits, Expr cond, List iters, Stmt body) { 310 For n = new For_c(pos, inits, cond, iters, body); 311 n = (For)n.ext(extFactory.extFor()); 312 n = (For)n.del(delFactory.delFor()); 313 return n; 314 } 315 316 public Formal Formal(Position pos, Flags flags, TypeNode type, String name) { 317 Formal n = new Formal_c(pos, flags, type, name); 318 n = (Formal)n.ext(extFactory.extFormal()); 319 n = (Formal)n.del(delFactory.delFormal()); 320 return n; 321 } 322 323 public If If(Position pos, Expr cond, Stmt consequent, Stmt alternative) { 324 If n = new If_c(pos, cond, consequent, alternative); 325 n = (If)n.ext(extFactory.extIf()); 326 n = (If)n.del(delFactory.delIf()); 327 return n; 328 } 329 330 public Import Import(Position pos, Import.Kind kind, String name) { 331 Import n = new Import_c(pos, kind, name); 332 n = (Import)n.ext(extFactory.extImport()); 333 n = (Import)n.del(delFactory.delImport()); 334 return n; 335 } 336 337 public Initializer Initializer(Position pos, Flags flags, Block body) { 338 Initializer n = new Initializer_c(pos, flags, body); 339 n = (Initializer)n.ext(extFactory.extInitializer()); 340 n = (Initializer)n.del(delFactory.delInitializer()); 341 return n; 342 } 343 344 public Instanceof Instanceof(Position pos, Expr expr, TypeNode type) { 345 Instanceof n = new Instanceof_c(pos, expr, type); 346 n = (Instanceof)n.ext(extFactory.extInstanceof()); 347 n = (Instanceof)n.del(delFactory.delInstanceof()); 348 return n; 349 } 350 351 public IntLit IntLit(Position pos, IntLit.Kind kind, long value) { 352 IntLit n = new IntLit_c(pos, kind, value); 353 n = (IntLit)n.ext(extFactory.extIntLit()); 354 n = (IntLit)n.del(delFactory.delIntLit()); 355 return n; 356 } 357 358 public Labeled Labeled(Position pos, String label, Stmt body) { 359 Labeled n = new Labeled_c(pos, label, body); 360 n = (Labeled)n.ext(extFactory.extLabeled()); 361 n = (Labeled)n.del(delFactory.delLabeled()); 362 return n; 363 } 364 365 public Local Local(Position pos, String name) { 366 Local n = new Local_c(pos, name); 367 n = (Local)n.ext(extFactory.extLocal()); 368 n = (Local)n.del(delFactory.delLocal()); 369 return n; 370 } 371 372 public LocalClassDecl LocalClassDecl(Position pos, ClassDecl decl) { 373 LocalClassDecl n = new LocalClassDecl_c(pos, decl); 374 n = (LocalClassDecl)n.ext(extFactory.extLocalClassDecl()); 375 n = (LocalClassDecl)n.del(delFactory.delLocalClassDecl()); 376 return n; 377 } 378 379 public LocalDecl LocalDecl(Position pos, Flags flags, TypeNode type, String name, Expr init) { 380 LocalDecl n = new LocalDecl_c(pos, flags, type, name, init); 381 n = (LocalDecl)n.ext(extFactory.extLocalDecl()); 382 n = (LocalDecl)n.del(delFactory.delLocalDecl()); 383 return n; 384 } 385 386 public MethodDecl MethodDecl(Position pos, Flags flags, TypeNode returnType, String name, List formals, List throwTypes, Block body) { 387 MethodDecl n = new MethodDecl_c(pos, flags, returnType, name, formals, throwTypes, body); 388 n = (MethodDecl)n.ext(extFactory.extMethodDecl()); 389 n = (MethodDecl)n.del(delFactory.delMethodDecl()); 390 return n; 391 } 392 393 public New New(Position pos, Expr outer, TypeNode objectType, List args, ClassBody body) { 394 New n = new New_c(pos, outer, objectType, args, body); 395 n = (New)n.ext(extFactory.extNew()); 396 n = (New)n.del(delFactory.delNew()); 397 return n; 398 } 399 400 public NewArray NewArray(Position pos, TypeNode base, List dims, int addDims, ArrayInit init) { 401 NewArray n = new NewArray_c(pos, base, dims, addDims, init); 402 n = (NewArray)n.ext(extFactory.extNewArray()); 403 n = (NewArray)n.del(delFactory.delNewArray()); 404 return n; 405 } 406 407 public NullLit NullLit(Position pos) { 408 NullLit n = new NullLit_c(pos); 409 n = (NullLit)n.ext(extFactory.extNullLit()); 410 n = (NullLit)n.del(delFactory.delNullLit()); 411 return n; 412 } 413 414 public Return Return(Position pos, Expr expr) { 415 Return n = new Return_c(pos, expr); 416 n = (Return)n.ext(extFactory.extReturn()); 417 n = (Return)n.del(delFactory.delReturn()); 418 return n; 419 } 420 421 public SourceCollection SourceCollection(Position pos, List sources) { 422 SourceCollection n = new SourceCollection_c(pos, sources); 423 n = (SourceCollection)n.ext(extFactory.extSourceCollection()); 424 n = (SourceCollection)n.del(delFactory.delSourceCollection()); 425 return n; 426 } 427 428 public SourceFile SourceFile(Position pos, PackageNode packageName, List imports, List decls) { 429 SourceFile n = new SourceFile_c(pos, packageName, imports, decls); 430 n = (SourceFile)n.ext(extFactory.extSourceFile()); 431 n = (SourceFile)n.del(delFactory.delSourceFile()); 432 return n; 433 } 434 435 public Special Special(Position pos, Special.Kind kind, TypeNode outer) { 436 Special n = new Special_c(pos, kind, outer); 437 n = (Special)n.ext(extFactory.extSpecial()); 438 n = (Special)n.del(delFactory.delSpecial()); 439 return n; 440 } 441 442 public StringLit StringLit(Position pos, String value) { 443 StringLit n = new StringLit_c(pos, value); 444 n = (StringLit)n.ext(extFactory.extStringLit()); 445 n = (StringLit)n.del(delFactory.delStringLit()); 446 return n; 447 } 448 449 public Switch Switch(Position pos, Expr expr, List elements) { 450 Switch n = new Switch_c(pos, expr, elements); 451 n = (Switch)n.ext(extFactory.extSwitch()); 452 n = (Switch)n.del(delFactory.delSwitch()); 453 return n; 454 } 455 456 public Synchronized Synchronized(Position pos, Expr expr, Block body) { 457 Synchronized n = new Synchronized_c(pos, expr, body); 458 n = (Synchronized)n.ext(extFactory.extSynchronized()); 459 n = (Synchronized)n.del(delFactory.delSynchronized()); 460 return n; 461 } 462 463 public Throw Throw(Position pos, Expr expr) { 464 Throw n = new Throw_c(pos, expr); 465 n = (Throw)n.ext(extFactory.extThrow()); 466 n = (Throw)n.del(delFactory.delThrow()); 467 return n; 468 } 469 470 public Try Try(Position pos, Block tryBlock, List catchBlocks, Block finallyBlock) { 471 Try n = new Try_c(pos, tryBlock, catchBlocks, finallyBlock); 472 n = (Try)n.ext(extFactory.extTry()); 473 n = (Try)n.del(delFactory.delTry()); 474 return n; 475 } 476 477 public ArrayTypeNode ArrayTypeNode(Position pos, TypeNode base) { 478 ArrayTypeNode n = new ArrayTypeNode_c(pos, base); 479 n = (ArrayTypeNode)n.ext(extFactory.extArrayTypeNode()); 480 n = (ArrayTypeNode)n.del(delFactory.delArrayTypeNode()); 481 return n; 482 } 483 484 public CanonicalTypeNode CanonicalTypeNode(Position pos, Type type) { 485 if (! type.isCanonical()) { 486 throw new InternalCompilerError("Cannot construct a canonical " + 487 "type node for a non-canonical type."); 488 } 489 490 CanonicalTypeNode n = new CanonicalTypeNode_c(pos, type); 491 n = (CanonicalTypeNode)n.ext(extFactory.extCanonicalTypeNode()); 492 n = (CanonicalTypeNode)n.del(delFactory.delCanonicalTypeNode()); 493 return n; 494 } 495 496 public PackageNode PackageNode(Position pos, Package p) { 497 PackageNode n = new PackageNode_c(pos, p); 498 n = (PackageNode)n.ext(extFactory.extPackageNode()); 499 n = (PackageNode)n.del(delFactory.delPackageNode()); 500 return n; 501 } 502 503 public Unary Unary(Position pos, Unary.Operator op, Expr expr) { 504 Unary n = new Unary_c(pos, op, expr); 505 n = (Unary)n.ext(extFactory.extUnary()); 506 n = (Unary)n.del(delFactory.delUnary()); 507 return n; 508 } 509 510 public While While(Position pos, Expr cond, Stmt body) { 511 While n = new While_c(pos, cond, body); 512 n = (While)n.ext(extFactory.extWhile()); 513 n = (While)n.del(delFactory.delWhile()); 514 return n; 515 } 516 } 517 | Popular Tags |