1 /** 2 * Redistribution and use in source and binary forms, with or without 3 * modification, are permitted provided that the following conditions are 4 * met : 5 * 6 * . Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * 9 * . Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * . The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 package cppast; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 34 /** 35 * Provides a composite for parser visitors. 36 * 37 * @author Mathieu Champlon 38 */ 39 public final class VisitorComposite implements ParserVisitor 40 { 41 private final List<ParserVisitor> visitors = new ArrayList<ParserVisitor>(); 42 43 /** 44 * Add a visitor to the composite. 45 * 46 * @param visitor the visitor to add 47 */ 48 public void register( final ParserVisitor visitor ) 49 { 50 visitors.add( visitor ); 51 } 52 53 /** 54 * {@inheritDoc} 55 */ 56 public Object visit( final SimpleNode node, final Object data ) 57 { 58 for( ParserVisitor visitor : visitors ) 59 visitor.visit( node, data ); 60 return data; 61 } 62 63 /** 64 * {@inheritDoc} 65 */ 66 public Object visit( final AstTranslationUnit node, final Object data ) 67 { 68 for( ParserVisitor visitor : visitors ) 69 visitor.visit( node, data ); 70 return data; 71 } 72 73 /** 74 * {@inheritDoc} 75 */ 76 public Object visit( final AstFunctionDefinition node, final Object data ) 77 { 78 for( ParserVisitor visitor : visitors ) 79 visitor.visit( node, data ); 80 return data; 81 } 82 83 /** 84 * {@inheritDoc} 85 */ 86 public Object visit( final AstFunctionName node, final Object data ) 87 { 88 for( ParserVisitor visitor : visitors ) 89 visitor.visit( node, data ); 90 return data; 91 } 92 93 /** 94 * {@inheritDoc} 95 */ 96 public Object visit( final AstDestructorDefinition node, final Object data ) 97 { 98 for( ParserVisitor visitor : visitors ) 99 visitor.visit( node, data ); 100 return data; 101 } 102 103 /** 104 * {@inheritDoc} 105 */ 106 public Object visit( final AstConstructorDefinition node, final Object data ) 107 { 108 for( ParserVisitor visitor : visitors ) 109 visitor.visit( node, data ); 110 return data; 111 } 112 113 /** 114 * {@inheritDoc} 115 */ 116 public Object visit( final AstCaseStatement node, final Object data ) 117 { 118 for( ParserVisitor visitor : visitors ) 119 visitor.visit( node, data ); 120 return data; 121 } 122 123 /** 124 * {@inheritDoc} 125 */ 126 public Object visit( final AstIfStatement node, final Object data ) 127 { 128 for( ParserVisitor visitor : visitors ) 129 visitor.visit( node, data ); 130 return data; 131 } 132 133 /** 134 * {@inheritDoc} 135 */ 136 public Object visit( final AstIterationStatement node, final Object data ) 137 { 138 for( ParserVisitor visitor : visitors ) 139 visitor.visit( node, data ); 140 return data; 141 } 142 143 /** 144 * {@inheritDoc} 145 */ 146 public Object visit( final AstCatchBlock node, final Object data ) 147 { 148 for( ParserVisitor visitor : visitors ) 149 visitor.visit( node, data ); 150 return data; 151 } 152 153 /** 154 * {@inheritDoc} 155 */ 156 public Object visit( final AstFunctionParameters node, final Object data ) 157 { 158 for( ParserVisitor visitor : visitors ) 159 visitor.visit( node, data ); 160 return data; 161 } 162 163 /** 164 * {@inheritDoc} 165 */ 166 public Object visit( final AstParameter node, final Object data ) 167 { 168 for( ParserVisitor visitor : visitors ) 169 visitor.visit( node, data ); 170 return data; 171 } 172 173 /** 174 * {@inheritDoc} 175 */ 176 public Object visit( final AstParameterType node, final Object data ) 177 { 178 for( ParserVisitor visitor : visitors ) 179 visitor.visit( node, data ); 180 return data; 181 } 182 183 /** 184 * {@inheritDoc} 185 */ 186 public Object visit( final AstParameterTypeQualifier node, final Object data ) 187 { 188 for( ParserVisitor visitor : visitors ) 189 visitor.visit( node, data ); 190 return data; 191 } 192 193 /** 194 * {@inheritDoc} 195 */ 196 public Object visit( final AstFunctionBody node, final Object data ) 197 { 198 for( ParserVisitor visitor : visitors ) 199 visitor.visit( node, data ); 200 return data; 201 } 202 203 /** 204 * {@inheritDoc} 205 */ 206 public Object visit( final AstConstructorInitializer node, final Object data ) 207 { 208 for( ParserVisitor visitor : visitors ) 209 visitor.visit( node, data ); 210 return data; 211 } 212 213 /** 214 * {@inheritDoc} 215 */ 216 public Object visit( final AstExpressionStatement node, final Object data ) 217 { 218 for( ParserVisitor visitor : visitors ) 219 visitor.visit( node, data ); 220 return data; 221 } 222 223 /** 224 * {@inheritDoc} 225 */ 226 public Object visit( final AstElseStatement node, final Object data ) 227 { 228 for( ParserVisitor visitor : visitors ) 229 visitor.visit( node, data ); 230 return data; 231 } 232 233 /** 234 * {@inheritDoc} 235 */ 236 public Object visit( final AstDeclarationStatement node, final Object data ) 237 { 238 for( ParserVisitor visitor : visitors ) 239 visitor.visit( node, data ); 240 return data; 241 } 242 243 /** 244 * {@inheritDoc} 245 */ 246 public Object visit( final AstSwitchStatement node, final Object data ) 247 { 248 for( ParserVisitor visitor : visitors ) 249 visitor.visit( node, data ); 250 return data; 251 } 252 253 /** 254 * {@inheritDoc} 255 */ 256 public Object visit( final AstGotoStatement node, final Object data ) 257 { 258 for( ParserVisitor visitor : visitors ) 259 visitor.visit( node, data ); 260 return data; 261 } 262 263 /** 264 * {@inheritDoc} 265 */ 266 public Object visit( final AstBreakStatement node, final Object data ) 267 { 268 for( ParserVisitor visitor : visitors ) 269 visitor.visit( node, data ); 270 return data; 271 } 272 273 /** 274 * {@inheritDoc} 275 */ 276 public Object visit( final AstReturnStatement node, final Object data ) 277 { 278 for( ParserVisitor visitor : visitors ) 279 visitor.visit( node, data ); 280 return data; 281 } 282 283 /** 284 * {@inheritDoc} 285 */ 286 public Object visit( final AstContinueStatement node, final Object data ) 287 { 288 for( ParserVisitor visitor : visitors ) 289 visitor.visit( node, data ); 290 return data; 291 } 292 293 /** 294 * {@inheritDoc} 295 */ 296 public Object visit( final AstLabelStatement node, final Object data ) 297 { 298 for( ParserVisitor visitor : visitors ) 299 visitor.visit( node, data ); 300 return data; 301 } 302 303 /** 304 * {@inheritDoc} 305 */ 306 public Object visit( final AstDefaultStatement node, final Object data ) 307 { 308 for( ParserVisitor visitor : visitors ) 309 visitor.visit( node, data ); 310 return data; 311 } 312 313 /** 314 * {@inheritDoc} 315 */ 316 public Object visit( final AstConditionalExpression node, final Object data ) 317 { 318 for( ParserVisitor visitor : visitors ) 319 visitor.visit( node, data ); 320 return data; 321 } 322 323 /** 324 * {@inheritDoc} 325 */ 326 public Object visit( final AstLogicalOrExpression node, final Object data ) 327 { 328 for( ParserVisitor visitor : visitors ) 329 visitor.visit( node, data ); 330 return data; 331 } 332 333 /** 334 * {@inheritDoc} 335 */ 336 public Object visit( final AstLogicalAndExpression node, final Object data ) 337 { 338 for( ParserVisitor visitor : visitors ) 339 visitor.visit( node, data ); 340 return data; 341 } 342 343 /** 344 * {@inheritDoc} 345 */ 346 public Object visit( final AstPrimaryExpression node, final Object data ) 347 { 348 for( ParserVisitor visitor : visitors ) 349 visitor.visit( node, data ); 350 return data; 351 } 352 353 /** 354 * {@inheritDoc} 355 */ 356 public Object visit( final AstAssignmentExpression node, final Object data ) 357 { 358 for( ParserVisitor visitor : visitors ) 359 visitor.visit( node, data ); 360 return data; 361 } 362 363 /** 364 * {@inheritDoc} 365 */ 366 public Object visit( final AstInclusiveOrExpression node, final Object data ) 367 { 368 for( ParserVisitor visitor : visitors ) 369 visitor.visit( node, data ); 370 return data; 371 } 372 373 /** 374 * {@inheritDoc} 375 */ 376 public Object visit( final AstExclusiveOrExpression node, final Object data ) 377 { 378 for( ParserVisitor visitor : visitors ) 379 visitor.visit( node, data ); 380 return data; 381 } 382 383 /** 384 * {@inheritDoc} 385 */ 386 public Object visit( final AstAndExpression node, final Object data ) 387 { 388 for( ParserVisitor visitor : visitors ) 389 visitor.visit( node, data ); 390 return data; 391 } 392 393 /** 394 * {@inheritDoc} 395 */ 396 public Object visit( final AstEqualityExpression node, final Object data ) 397 { 398 for( ParserVisitor visitor : visitors ) 399 visitor.visit( node, data ); 400 return data; 401 } 402 403 /** 404 * {@inheritDoc} 405 */ 406 public Object visit( final AstRelationalExpression node, final Object data ) 407 { 408 for( ParserVisitor visitor : visitors ) 409 visitor.visit( node, data ); 410 return data; 411 } 412 413 /** 414 * {@inheritDoc} 415 */ 416 public Object visit( final AstShiftExpression node, final Object data ) 417 { 418 for( ParserVisitor visitor : visitors ) 419 visitor.visit( node, data ); 420 return data; 421 } 422 423 /** 424 * {@inheritDoc} 425 */ 426 public Object visit( final AstAdditiveExpression node, final Object data ) 427 { 428 for( ParserVisitor visitor : visitors ) 429 visitor.visit( node, data ); 430 return data; 431 } 432 433 /** 434 * {@inheritDoc} 435 */ 436 public Object visit( final AstMultiplicativeExpression node, final Object data ) 437 { 438 for( ParserVisitor visitor : visitors ) 439 visitor.visit( node, data ); 440 return data; 441 } 442 443 /** 444 * {@inheritDoc} 445 */ 446 public Object visit( final AstPointerToMemberExpression node, final Object data ) 447 { 448 for( ParserVisitor visitor : visitors ) 449 visitor.visit( node, data ); 450 return data; 451 } 452 453 /** 454 * {@inheritDoc} 455 */ 456 public Object visit( final AstCastExpression node, final Object data ) 457 { 458 for( ParserVisitor visitor : visitors ) 459 visitor.visit( node, data ); 460 return data; 461 } 462 463 /** 464 * {@inheritDoc} 465 */ 466 public Object visit( final AstUnaryExpression node, final Object data ) 467 { 468 for( ParserVisitor visitor : visitors ) 469 visitor.visit( node, data ); 470 return data; 471 } 472 473 /** 474 * {@inheritDoc} 475 */ 476 public Object visit( final AstPostfixExpression node, final Object data ) 477 { 478 for( ParserVisitor visitor : visitors ) 479 visitor.visit( node, data ); 480 return data; 481 } 482 483 /** 484 * {@inheritDoc} 485 */ 486 public Object visit( final AstIdExpression node, final Object data ) 487 { 488 for( ParserVisitor visitor : visitors ) 489 visitor.visit( node, data ); 490 return data; 491 } 492 493 /** 494 * {@inheritDoc} 495 */ 496 public Object visit( final AstNewExpression node, final Object data ) 497 { 498 for( ParserVisitor visitor : visitors ) 499 visitor.visit( node, data ); 500 return data; 501 } 502 503 /** 504 * {@inheritDoc} 505 */ 506 public Object visit( final AstDeleteExpression node, final Object data ) 507 { 508 for( ParserVisitor visitor : visitors ) 509 visitor.visit( node, data ); 510 return data; 511 } 512 513 /** 514 * {@inheritDoc} 515 */ 516 public Object visit( final AstFunctionCallExpression node, final Object data ) 517 { 518 for( ParserVisitor visitor : visitors ) 519 visitor.visit( node, data ); 520 return data; 521 } 522 523 /** 524 * {@inheritDoc} 525 */ 526 public Object visit( final AstConstantExpression node, final Object data ) 527 { 528 for( ParserVisitor visitor : visitors ) 529 visitor.visit( node, data ); 530 return data; 531 } 532 533 /** 534 * {@inheritDoc} 535 */ 536 public Object visit( final AstTypeIdExpression node, final Object data ) 537 { 538 for( ParserVisitor visitor : visitors ) 539 visitor.visit( node, data ); 540 return data; 541 } 542 543 /** 544 * {@inheritDoc} 545 */ 546 public Object visit( final AstThrowExpression node, final Object data ) 547 { 548 for( ParserVisitor visitor : visitors ) 549 visitor.visit( node, data ); 550 return data; 551 } 552 553 /** 554 * {@inheritDoc} 555 */ 556 public Object visit( final AstClassDefinition node, final Object data ) 557 { 558 for( ParserVisitor visitor : visitors ) 559 visitor.visit( node, data ); 560 return data; 561 } 562 563 /** 564 * {@inheritDoc} 565 */ 566 public Object visit( final AstNamespaceDefinition node, final Object data ) 567 { 568 for( ParserVisitor visitor : visitors ) 569 visitor.visit( node, data ); 570 return data; 571 } 572 573 /** 574 * {@inheritDoc} 575 */ 576 public Object visit( final AstNamespaceAliasDefinition node, final Object data ) 577 { 578 for( ParserVisitor visitor : visitors ) 579 visitor.visit( node, data ); 580 return data; 581 } 582 583 /** 584 * {@inheritDoc} 585 */ 586 public Object visit( final AstClassDeclaration node, final Object data ) 587 { 588 for( ParserVisitor visitor : visitors ) 589 visitor.visit( node, data ); 590 return data; 591 } 592 593 /** 594 * {@inheritDoc} 595 */ 596 public Object visit( final AstEnumSpecifier node, final Object data ) 597 { 598 for( ParserVisitor visitor : visitors ) 599 visitor.visit( node, data ); 600 return data; 601 } 602 603 /** 604 * {@inheritDoc} 605 */ 606 public Object visit( final AstDeclaration node, final Object data ) 607 { 608 for( ParserVisitor visitor : visitors ) 609 visitor.visit( node, data ); 610 return data; 611 } 612 613 /** 614 * {@inheritDoc} 615 */ 616 public Object visit( final AstMemberDeclaration node, final Object data ) 617 { 618 for( ParserVisitor visitor : visitors ) 619 visitor.visit( node, data ); 620 return data; 621 } 622 623 /** 624 * {@inheritDoc} 625 */ 626 public Object visit( final AstFunctionDeclaration node, final Object data ) 627 { 628 for( ParserVisitor visitor : visitors ) 629 visitor.visit( node, data ); 630 return data; 631 } 632 633 /** 634 * {@inheritDoc} 635 */ 636 public Object visit( final AstConstructorDeclaration node, final Object data ) 637 { 638 for( ParserVisitor visitor : visitors ) 639 visitor.visit( node, data ); 640 return data; 641 } 642 643 /** 644 * {@inheritDoc} 645 */ 646 public Object visit( final AstDestructorDeclaration node, final Object data ) 647 { 648 for( ParserVisitor visitor : visitors ) 649 visitor.visit( node, data ); 650 return data; 651 } 652 653 /** 654 * {@inheritDoc} 655 */ 656 public Object visit( final AstTryBlock node, final Object data ) 657 { 658 for( ParserVisitor visitor : visitors ) 659 visitor.visit( node, data ); 660 return data; 661 } 662 663 /** 664 * {@inheritDoc} 665 */ 666 public Object visit( final AstFunctionPointerPostfix node, final Object data ) 667 { 668 for( ParserVisitor visitor : visitors ) 669 visitor.visit( node, data ); 670 return data; 671 } 672 }