Synopsis - Cross-Reference
File: /Synopsis/Parsers/IDL/idl.yy1// -*- c++ -*- 2// Package : omniidl 3// idl.yy Created on: 1999/10/05 4// Author : Duncan Grisby (dpg1) 5// 6// Copyright (C) 1999 AT&T Laboratories Cambridge 7// 8// This file is part of omniidl. 9// 10// omniidl is free software; you can redistribute it and/or modify it 11// under the terms of the GNU General Public License as published by 12// the Free Software Foundation; either version 2 of the License, or 13// (at your option) any later version. 14// 15// This program is distributed in the hope that it will be useful, 16// but WITHOUT ANY WARRANTY; without even the implied warranty of 17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18// General Public License for more details. 19// 20// You should have received a copy of the GNU General Public License 21// along with this program; if not, write to the Free Software 22// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 23// 02111-1307, USA. 24// 25// Description: 26// 27// Bison parser 28 29// $Id: idl.yy,v 1.15.2.2 2003/09/04 14:00:23 dgrisby Exp $ 30// $Log: idl.yy,v $ 31// Revision 1.15.2.2 2003/09/04 14:00:23 dgrisby 32// ValueType IDL updates. 33// 34// Revision 1.15.2.1 2003/03/23 21:01:48 dgrisby 35// Start of omniORB 4.1.x development branch. 36// 37// Revision 1.11.2.7 2001/08/29 11:54:19 dpg1 38// Clean up const handling in IDL compiler. 39// 40// Revision 1.11.2.6 2001/03/13 10:32:10 dpg1 41// Fixed point support. 42// 43// Revision 1.11.2.5 2000/12/05 17:45:18 dpg1 44// omniidl case sensitivity updates from omni3_develop. 45// 46// Revision 1.11.2.4 2000/11/01 12:45:55 dpg1 47// Update to CORBA 2.4 specification. 48// 49// Revision 1.11.2.3 2000/10/27 16:31:07 dpg1 50// Clean up of omniidl dependencies and types, from omni3_develop. 51// 52// Revision 1.11.2.2 2000/10/10 10:18:50 dpg1 53// Update omniidl front-end from omni3_develop. 54// 55// Revision 1.9.2.5 2000/08/01 11:27:45 dpg1 56// Comments were incorrectly attached to struct members. 57// 58// Revision 1.9.2.4 2000/06/09 11:20:47 dpg1 59// Last fix put __omni_pragma line numbers off by one... 60// 61// Revision 1.9.2.3 2000/06/08 14:58:19 dpg1 62// Line numbers for #pragmas and // comments were off by one 63// 64// Revision 1.9.2.2 2000/06/08 14:36:19 dpg1 65// Comments and pragmas are now objects rather than plain strings, so 66// they can have file,line associated with them. 67// 68// Revision 1.9.2.1 2000/06/05 18:13:26 dpg1 69// Comments can be attached to subsequent declarations (with -K). Better 70// idea of most recent decl in operation declarations 71// 72// Revision 1.9 2000/02/04 12:17:09 dpg1 73// Support for VMS. 74// 75// Revision 1.8 1999/12/28 18:16:07 dpg1 76// positive_int_const isn't allowed to be zero. 77// 78// Revision 1.7 1999/11/17 17:17:00 dpg1 79// Changes to remove static initialisation of objects. 80// 81// Revision 1.6 1999/11/04 17:16:55 dpg1 82// Changes for NT. 83// 84// Revision 1.5 1999/11/03 17:24:05 dpg1 85// Added optional pragmas all over the place. 86// 87// Revision 1.4 1999/11/02 17:07:28 dpg1 88// Changes to compile on Solaris. 89// 90// Revision 1.3 1999/11/01 20:19:57 dpg1 91// Support for union switch types declared inside the switch statement. 92// 93// Revision 1.2 1999/10/29 15:41:31 dpg1 94// DeclaredType() now takes extra DeclRepoId* argument. 95// 96// Revision 1.1 1999/10/27 14:06:00 dpg1 97// *** empty log message *** 98// 99 100%{ 101 102#include <stdlib.h> 103#include <string.h> 104 105#include <idlutil.h> 106#include <idlerr.h> 107#include <idlrepoId.h> 108#include <idlscope.h> 109#include <idltype.h> 110#include <idlexpr.h> 111#include <idlast.h> 112 113#define YYDEBUG 1 114 115// Globals from lexer 116extern int yylineno; 117extern char* currentFile; 118extern IDL_Boolean mainFile; 119 120void yyerror(char *s) { 121} 122extern int yylex(); 123 124// Nasty hack for abstract valuetypes 125ValueAbs* valueabs_hack = 0; 126 127#ifdef __VMS 128/* Apparently, __ALLOCA is defined for some versions of the C (but not C++) 129 compiler on VAX. */ 130#if defined(__ALPHA) || defined(__DECC) && __DECC_VER >= 60000000 131#include <builtins.h> 132#define alloca __ALLOCA 133#else 134#define alloca malloc 135#endif 136#endif 137 138%} 139 140%union { 141 char* id_val; 142 int int_val; 143 IDL_ULong ulong_val; 144 IdlIntLiteral int_literal_val; 145#ifndef __VMS 146 IdlFloatLiteral float_literal_val; 147#else 148 double float_literal_val; 149#endif 150 char char_val; 151 char* string_val; 152 IDL_WChar wchar_val; 153 IDL_WChar* wstring_val; 154 IDL_Boolean boolean_val; 155 IDL_Fixed* fixed_val; 156 IdlType* type_val; 157 TypeSpec* type_spec_val; 158 IdlExpr* expr_val; 159 ScopedName* scopedname_val; 160 Decl* decl_val; 161 Module* module_val; 162 Interface* interface_val; 163 InheritSpec* inheritspec_val; 164 Forward* forward_val; 165 Const* const_val; 166 Typedef* typedef_val; 167 Struct* struct_val; 168 Exception* exception_val; 169 Member* member_val; 170 Declarator* declarator_val; 171 Union* union_val; 172 UnionCase* union_case_val; 173 CaseLabel* case_label_val; 174 ValueBase* value_base_val; 175 Value* value_val; 176 ValueForward* value_forward_val; 177 ValueBox* value_box_val; 178 ValueAbs* value_abs_val; 179 ValueInheritSpec* valueinheritspec_val; 180 ValueInheritSupportSpec* valueinheritsupportspec_val; 181 StateMember* statemember_val; 182 Factory* factory_val; 183 Enumerator* enumerator_val; 184 Enum* enum_val; 185 ArraySize* array_size_val; 186 Attribute* attribute_val; 187 Operation* operation_val; 188 Parameter* parameter_val; 189 RaisesSpec* raisesspec_val; 190 ContextSpec* contextspec_val; 191} 192 193%token <id_val> IDENTIFIER 194 195// Keywords 196%token ABSTRACT 197%token ANY 198%token ATTRIBUTE 199%token BOOLEAN 200%token CASE 201%token CHAR 202%token CONST 203%token CONTEXT 204%token CUSTOM 205%token DEFAULT 206%token DOUBLE 207%token ENUM 208%token EXCEPTION 209%token FACTORY 210%token FALSE_ 211%token FIXED 212%token FLOAT 213%token IN 214%token INOUT 215%token INTERFACE 216%token LOCAL 217%token LONG 218%token MODULE 219%token NATIVE 220%token OBJECT 221%token OCTET 222%token ONEWAY 223%token OUT 224%token PRIVATE 225%token PUBLIC 226%token RAISES 227%token READONLY 228%token SEQUENCE 229%token SHORT 230%token STRING 231%token STRUCT 232%token SUPPORTS 233%token SWITCH 234%token TRUE_ 235%token TRUNCATABLE 236%token TYPEDEF 237%token UNION 238%token UNSIGNED 239%token VALUEBASE 240%token VALUETYPE 241%token VOID 242%token WCHAR 243%token WSTRING 244 245// Pragmas 246%token PRAGMA 247%token PRAGMA_PREFIX 248%token PRAGMA_ID 249%token PRAGMA_VERSION 250%token OMNI_PRAGMA 251%token END_PRAGMA 252%token <string_val> UNKNOWN_PRAGMA_BODY 253 254// Literals 255%token <int_literal_val> INTEGER_LITERAL 256%token <char_val> CHARACTER_LITERAL 257%token <wchar_val> WIDE_CHARACTER_LITERAL 258%token <float_literal_val> FLOATING_PT_LITERAL 259%token <string_val> STRING_LITERAL 260%token <wstring_val> WIDE_STRING_LITERAL 261%token <fixed_val> FIXED_PT_LITERAL 262 263// Scope delimiter 264%token SCOPE_DELIM 265 266// Operators 267%token LEFT_SHIFT 268%token RIGHT_SHIFT 269 270// Types of nonterminals 271%type <decl_val> start 272%type <decl_val> definition_plus 273%type <decl_val> definition 274%type <module_val> module 275%type <module_val> module_header 276%type <decl_val> interface 277%type <interface_val> interface_dcl 278%type <forward_val> forward_dcl 279%type <interface_val> interface_header 280%type <decl_val> interface_body 281%type <decl_val> export_star 282%type <decl_val> export 283%type <inheritspec_val> interface_inheritance_spec_opt 284%type <inheritspec_val> interface_inheritance_spec 285%type <inheritspec_val> interface_inheritance_list 286%type <scopedname_val> interface_name 287%type <scopedname_val> scoped_name 288%type <value_base_val> value 289%type <value_forward_val> value_forward_dcl 290%type <int_val> abstract_local_opt 291%type <value_box_val> value_box_dcl 292%type <value_abs_val> value_abs_dcl 293%type <value_val> value_dcl 294%type <value_val> value_header 295%type <valueinheritsupportspec_val> value_inheritance_spec 296%type <valueinheritspec_val> value_value_inheritance_spec 297%type <boolean_val> truncatable_opt 298%type <valueinheritspec_val> value_inheritance_list 299%type <scopedname_val> value_name 300%type <decl_val> value_element_star 301%type <decl_val> value_element 302%type <statemember_val> state_member 303%type <ulong_val> member_access 304%type <factory_val> init_dcl 305%type <factory_val> init_dcl_header 306%type <parameter_val> init_param_decls_opt 307%type <parameter_val> init_param_decls 308%type <parameter_val> init_param_decl 309%type <const_val> const_dcl 310%type <type_val> const_type 311%type <expr_val> const_exp 312%type <expr_val> or_expr 313%type <expr_val> xor_expr 314%type <expr_val> and_expr 315%type <expr_val> shift_expr 316%type <expr_val> add_expr 317%type <expr_val> mult_expr 318%type <expr_val> unary_expr 319%type <char_val> unary_operator 320%type <expr_val> primary_expr 321%type <expr_val> literal 322%type <boolean_val> boolean_literal 323%type <string_val> string_literal_plus 324%type <wstring_val> wide_string_literal_plus 325%type <ulong_val> positive_int_const 326%type <decl_val> type_dcl 327%type <typedef_val> type_declarator 328%type <type_spec_val> type_spec 329%type <type_val> simple_type_spec 330%type <type_val> base_type_spec 331%type <type_val> template_type_spec 332%type <type_val> constr_type_spec 333%type <declarator_val> declarators 334%type <declarator_val> declarator 335%type <declarator_val> simple_declarator 336%type <declarator_val> complex_declarator 337%type <type_val> floating_pt_type 338%type <type_val> integer_type 339%type <type_val> signed_int 340%type <type_val> signed_short_int 341%type <type_val> signed_long_int 342%type <type_val> signed_long_long_int 343%type <type_val> unsigned_int 344%type <type_val> unsigned_short_int 345%type <type_val> unsigned_long_int 346%type <type_val> unsigned_long_long_int 347%type <type_val> char_type 348%type <type_val> wide_char_type 349%type <type_val> boolean_type 350%type <type_val> octet_type 351%type <type_val> any_type 352%type <type_val> object_type 353%type <struct_val> struct_type 354%type <struct_val> struct_header 355%type <member_val> member_list 356%type <member_val> member 357%type <union_val> union_type 358%type <union_val> union_header 359%type <type_spec_val> switch_type_spec 360%type <union_case_val> switch_body 361%type <union_case_val> case_plus 362%type <union_case_val> case 363%type <case_label_val> case_label_plus 364%type <case_label_val> case_label 365%type <union_case_val> element_spec 366%type <enum_val> enum_type 367%type <enum_val> enum_header 368%type <enumerator_val> enumerator_list 369%type <enumerator_val> enumerator 370%type <type_val> sequence_type 371%type <type_val> string_type 372%type <type_val> wide_string_type 373%type <declarator_val> array_declarator 374%type <array_size_val> fixed_array_size_plus 375%type <array_size_val> fixed_array_size 376%type <attribute_val> attr_dcl 377%type <boolean_val> readonly_opt 378%type <declarator_val> simple_declarator_list 379%type <exception_val> except_dcl 380%type <exception_val> except_header 381%type <member_val> member_star 382%type <operation_val> op_dcl 383%type <operation_val> op_header 384%type <boolean_val> op_attribute_opt 385%type <boolean_val> op_attribute 386%type <type_val> op_type_spec 387%type <parameter_val> parameter_dcls 388%type <parameter_val> param_dcl_list 389%type <parameter_val> param_dcl 390%type <int_val> param_attribute 391%type <raisesspec_val> raises_expr_opt 392%type <raisesspec_val> raises_expr 393%type <raisesspec_val> scoped_name_list 394%type <contextspec_val> context_expr_opt 395%type <contextspec_val> context_expr 396%type <contextspec_val> string_literal_list 397%type <type_val> param_type_spec 398%type <type_val> fixed_pt_type 399%type <type_val> fixed_pt_const_type 400%type <type_val> value_base_type 401%type <decl_val> constr_forward_decl 402%type <string_val> unknown_pragma_body_plus 403 404%% 405 406start: 407 /* empty */ { $$ = 0; } 408 | definition_plus { 409 $$ = $1; 410 AST::tree()->setDeclarations($1); 411 } 412 ; 413 414definition_plus: 415 definition { $$ = $1; } 416 | definition_plus definition { 417 if ($1) { $1->append($2); $$ = $1; } 418 else $$ = $2; 419 } 420 ; 421 422definition: 423 type_dcl ';' { $$ = $1; } 424 | const_dcl ';' { $$ = $1; } 425 | except_dcl ';' { $$ = $1; } 426 | interface ';' { $$ = $1; } 427 | module ';' { $$ = $1; } 428 | value ';' { $$ = $1; } 429 | pragma { $$ = 0; } 430 | pragma_prefix { $$ = 0; } 431 | error { 432 IdlSyntaxError(currentFile, yylineno, "Syntax error in definition"); 433 $$ = 0; 434 } 435 ; 436 437module: 438 module_header pragmas_opt '{' definition_plus '}' { 439 $1->finishConstruction($4); 440 $$ = $1; 441 } 442 | module_header error { 443 IdlSyntaxError(currentFile, yylineno, 444 "Syntax error in module definition"); 445 } '{' definition_plus '}' { 446 $1->finishConstruction($5); 447 $$ = $1; 448 } 449 | module_header error { 450 IdlSyntaxError(currentFile, yylineno, 451 "Syntax error in module definition (no body found)"); 452 $1->finishConstruction(0); 453 $$ = $1; 454 } 455 ; 456 457module_header: 458 MODULE IDENTIFIER { $$ = new Module(currentFile, yylineno, mainFile, $2); } 459 ; 460 461interface: 462 interface_dcl { $$ = $1; } 463 | forward_dcl { $$ = $1; } 464 ; 465 466interface_dcl: 467 interface_header '{' interface_body '}' { 468 $1->finishConstruction($3); 469 $$ = $1; 470 } 471 | interface_header error { 472 IdlSyntaxError(currentFile, yylineno, 473 "Syntax error in interface definition"); 474 } '{' interface_body '}' { 475 $1->finishConstruction($5); 476 $$ = $1; 477 } 478 | interface_header error { 479 IdlSyntaxError(currentFile, yylineno, 480 "Syntax error in interface definition (no body found)"); 481 $1->finishConstruction(0); 482 $$ = $1; 483 } 484 ; 485 486forward_dcl: 487 abstract_local_opt INTERFACE IDENTIFIER { 488 $$ = new Forward(currentFile, yylineno, mainFile, $3, $1==1, $1==2); 489 } 490 ; 491 492interface_header: 493 abstract_local_opt INTERFACE IDENTIFIER pragmas_opt 494 interface_inheritance_spec_opt { 495 $$ = new Interface(currentFile, yylineno, mainFile, 496 $3, $1==1, $1==2, $5); 497 } 498 ; 499 500abstract_local_opt: 501 /* empty */ { $$ = 0; } 502 | ABSTRACT { $$ = 1; } 503 | LOCAL { $$ = 2; } 504 ; 505 506interface_body: 507 export_star { $$ = $1; } 508 ; 509 510export_star: 511 /* empty */ { $$ = 0; } 512 | export_star export { 513 if ($1) { $1->append($2); $$ = $1; } 514 else $$ = $2; 515 } 516 ; 517 518export: 519 type_dcl ';' { $$ = $1; } 520 | const_dcl ';' { $$ = $1; } 521 | except_dcl ';' { $$ = $1; } 522 | attr_dcl ';' { $$ = $1; } 523 | op_dcl ';' { $$ = $1; } 524 | pragma { $$ = 0; } 525 | error { 526 IdlSyntaxError(currentFile, yylineno, "Syntax error in interface body"); 527 $$ = 0; 528 } 529 ; 530 531interface_inheritance_spec_opt: 532 /* empty */ { $$ = 0; } 533 | interface_inheritance_spec { $$ = $1; } 534 ; 535 536interface_inheritance_spec: 537 ':' interface_inheritance_list { $$ = $2; } 538 ; 539 540interface_inheritance_list: 541 interface_name pragmas_opt { 542 $$ = new InheritSpec($1, currentFile, yylineno); 543 if (!$$->interface()) { 544 delete $$; 545 $$ = 0; 546 } 547 } 548 | interface_inheritance_list ',' pragmas_opt interface_name pragmas_opt { 549 if ($1) { 550 $1->append(new InheritSpec($4, currentFile, yylineno), 551 currentFile, yylineno); 552 $$ = $1; 553 } 554 else $$ = new InheritSpec($4, currentFile, yylineno); 555 } 556 | error { 557 IdlSyntaxError(currentFile, yylineno, 558 "Syntax error in inheritance list"); 559 $$ = 0; 560 } 561 ; 562 563interface_name: 564 scoped_name { $$ = $1; } 565 ; 566 567scoped_name: 568 IDENTIFIER { 569 $$ = new ScopedName($1, 0); 570 } 571 | SCOPE_DELIM IDENTIFIER { 572 $$ = new ScopedName($2, 1); 573 } 574 | scoped_name SCOPE_DELIM IDENTIFIER { 575 $1->append($3); 576 $$=$1; 577 } 578 ; 579 580/* The obvious way to specify valuetypes isn't LALR(1), but the 581 following is: 582*/ 583 584value: 585 value_dcl { $$ = $1; } 586 | value_abs_dcl { $$ = $1; } 587 | value_box_dcl { $$ = $1; } 588 | value_forward_dcl { $$ = $1; } 589 ; 590 591value_forward_dcl: 592 VALUETYPE IDENTIFIER { 593 $$ = new ValueForward(currentFile, yylineno, mainFile, 0, $2); 594 } 595 | ABSTRACT VALUETYPE IDENTIFIER { 596 $$ = new ValueForward(currentFile, yylineno, mainFile, 1, $3); 597 } 598 ; 599 600value_box_dcl: 601 VALUETYPE IDENTIFIER type_spec { 602 $$ = new ValueBox(currentFile, yylineno, mainFile, 603 $2, $3->type(), $3->constr()); 604 delete $3; 605 } 606 ; 607 608value_abs_dcl: 609 ABSTRACT VALUETYPE IDENTIFIER { 610 valueabs_hack = new ValueAbs(currentFile, yylineno, mainFile, $3, 0, 0); 611 } '{' export_star '}' { 612 valueabs_hack->finishConstruction($6); 613 $$ = valueabs_hack; 614 valueabs_hack = 0; 615 } 616 | ABSTRACT VALUETYPE IDENTIFIER value_inheritance_spec { 617 valueabs_hack = new ValueAbs(currentFile, yylineno, mainFile, $3, 618 $4->inherits(), $4->supports()); 619 delete $4; 620 } '{' export_star '}' { 621 valueabs_hack->finishConstruction($7); 622 $$ = valueabs_hack; 623 valueabs_hack = 0; 624 } 625 | error { 626 IdlSyntaxError(currentFile, yylineno, 627 "Syntax error in abstract valuetype"); 628 if (valueabs_hack) { 629 valueabs_hack->finishConstruction(0); 630 $$ = valueabs_hack; 631 valueabs_hack = 0; 632 } 633 else $$ = 0; 634 } 635 ; 636 637value_dcl: 638 value_header '{' value_element_star '}' { 639 $1->finishConstruction($3); 640 $$ = $1; 641 } 642 ; 643 644value_header: 645 VALUETYPE IDENTIFIER value_inheritance_spec { 646 $$ = new Value(currentFile, yylineno, mainFile, 0, $2, 647 $3->inherits(), $3->supports()); 648 delete $3; 649 } 650 | CUSTOM VALUETYPE IDENTIFIER value_inheritance_spec { 651 $$ = new Value(currentFile, yylineno, mainFile, 1, $3, 652 $4->inherits(), $4->supports()); 653 delete $4; 654 } 655 | VALUETYPE IDENTIFIER { 656 $$ = new Value(currentFile, yylineno, mainFile, 0, $2, 0, 0); 657 } 658 | CUSTOM VALUETYPE IDENTIFIER { 659 $$ = new Value(currentFile, yylineno, mainFile, 1, $3, 0, 0); 660 } 661 ; 662 663value_inheritance_spec: 664 ':' value_value_inheritance_spec SUPPORTS interface_inheritance_list { 665 $$ = new ValueInheritSupportSpec($2, $4); 666 } 667 | ':' value_value_inheritance_spec { 668 $$ = new ValueInheritSupportSpec($2, 0); 669 } 670 | SUPPORTS interface_inheritance_list { 671 $$ = new ValueInheritSupportSpec(0, $2); 672 } 673 ; 674 675value_value_inheritance_spec: 676 truncatable_opt value_inheritance_list { 677 if ($1) $2->setTruncatable(); 678 $$ = $2; 679 } 680 ; 681 682truncatable_opt: 683 /* empty */ { $$ = 0; } 684 | TRUNCATABLE { $$ = 1; } 685 ; 686 687value_inheritance_list: 688 value_name { 689 $$ = new ValueInheritSpec($1, currentFile, yylineno); 690 if (!$$->value()) { 691 delete $$; 692 $$ = 0; 693 } 694 } 695 | value_inheritance_list ',' value_name { 696 if ($1) { 697 $1->append(new ValueInheritSpec($3, currentFile, yylineno), 698 currentFile, yylineno); 699 $$ = $1; 700 } 701 else $$ = new ValueInheritSpec($3, currentFile, yylineno); 702 } 703 ; 704 705value_name: 706 scoped_name { $$ = $1; } 707 ; 708 709value_element_star: 710 /* empty */ { $$ = 0; } 711 | value_element_star value_element { 712 if ($1) { $1->append($2); $$ = $1; } 713 else $$ = $2; 714 } 715 ; 716 717value_element: 718 export { $$ = $1; } 719 | state_member { $$ = $1; } 720 | init_dcl { $$ = $1; } 721 ; 722 723state_member: 724 member_access type_spec declarators ';' { 725 $$ = new StateMember(currentFile, yylineno, mainFile, 726 $1, $2->type(), $2->constr(), $3); 727 delete $2; 728 } 729 ; 730 731member_access: 732 PUBLIC { $$ = 0; } 733 | PRIVATE { $$ = 1; } 734 ; 735 736init_dcl: 737 init_dcl_header '(' init_param_decls_opt ')' { 738 $1->closeParens(); 739 } raises_expr_opt ';' { 740 $1->finishConstruction($3, $6); 741 $$ = $1; 742 } 743 | init_dcl_header '(' error ')' { 744 $1->closeParens(); 745 } ';' { 746 IdlSyntaxError(currentFile, yylineno, 747 "Syntax error in factory parameters"); 748 $1->finishConstruction(0, 0); 749 $$ = $1; 750 } 751 ; 752 753init_dcl_header: 754 FACTORY IDENTIFIER { 755 $$ = new Factory(currentFile, yylineno, mainFile, $2); 756 } 757 ; 758 759init_param_decls_opt: 760 /* empty */ { $$ = 0; } 761 | init_param_decls { $$ = $1; } 762 ; 763 764init_param_decls: 765 init_param_decl { $$ = $1; } 766 | init_param_decls ',' init_param_decl { 767 if ($1) { $1->append($3); $$ = $1; } 768 else $$ = $3; 769 } 770 ; 771 772init_param_decl: 773 IN param_type_spec IDENTIFIER { 774 $$ = new Parameter(currentFile, yylineno, mainFile, 0, $2, $3); 775 } 776 ; 777 778// End of ValueType nastiness 779 780const_dcl: 781 CONST const_type IDENTIFIER '=' const_exp { 782 $$ = new Const(currentFile, yylineno, mainFile, $2, $3, $5); 783 } 784 ; 785 786const_type: 787 integer_type { $$ = $1; } 788 | char_type { $$ = $1; } 789 | wide_char_type { $$ = $1; } 790 | boolean_type { $$ = $1; } 791 | floating_pt_type { $$ = $1; } 792 | string_type { $$ = $1; } 793 | wide_string_type { $$ = $1; } 794 | fixed_pt_const_type { $$ = $1; } 795 | scoped_name { 796 $$ = IdlType::scopedNameToType(currentFile, yylineno, $1); 797 } 798 | octet_type { $$ = $1; } 799 ; 800 801const_exp: 802 or_expr { $$ = $1; } 803 ; 804 805or_expr: 806 xor_expr { $$ = $1; } 807 | or_expr '|' xor_expr { $$ = new OrExpr(currentFile, yylineno, $1, $3); } 808 ; 809 810xor_expr: 811 and_expr { $$ = $1; } 812 | xor_expr '^' and_expr { $$ = new XorExpr(currentFile, yylineno, $1, $3); } 813 ; 814 815and_expr: 816 shift_expr { $$ = $1; } 817 | and_expr '&' shift_expr { 818 $$ = new AndExpr(currentFile, yylineno, $1, $3); 819 } 820 ; 821 822shift_expr: 823 add_expr { $$ = $1; } 824 | shift_expr RIGHT_SHIFT add_expr { 825 $$ = new RShiftExpr(currentFile, yylineno, $1, $3); 826 } 827 | shift_expr LEFT_SHIFT add_expr { 828 $$ = new LShiftExpr(currentFile, yylineno, $1, $3); 829 } 830 ; 831 832add_expr: 833 mult_expr { $$ = $1; } 834 | add_expr '+' mult_expr { $$ = new AddExpr(currentFile, yylineno, $1, $3); } 835 | add_expr '-' mult_expr { $$ = new SubExpr(currentFile, yylineno, $1, $3); } 836 ; 837 838mult_expr: 839 unary_expr { $$ = $1; } 840 | mult_expr '*' unary_expr { 841 $$ = new MultExpr(currentFile, yylineno, $1, $3); 842 } 843 | mult_expr '/' unary_expr { 844 $$ = new DivExpr(currentFile, yylineno, $1, $3); 845 } 846 | mult_expr '%' unary_expr { 847 $$ = new ModExpr(currentFile, yylineno, $1, $3); 848 } 849 ; 850 851unary_expr: 852 unary_operator primary_expr { 853 if ($1 == '-') $$ = new MinusExpr(currentFile, yylineno, $2); 854 if ($1 == '+') $$ = new PlusExpr(currentFile, yylineno, $2); 855 if ($1 == '~') $$ = new InvertExpr(currentFile, yylineno, $2); 856 } 857 | primary_expr { $$ = $1; } 858 ; 859 860unary_operator: 861 '-' { $$ = '-'; } 862 | '+' { $$ = '+'; } 863 | '~' { $$ = '~'; } 864 ; 865 866primary_expr: 867 scoped_name { 868 $$ = IdlExpr::scopedNameToExpr(currentFile, yylineno, $1); 869 } 870 | literal { $$ = $1; } 871 | '(' const_exp ')' { $$ = $2; } 872 ; 873 874literal: 875 INTEGER_LITERAL { 876 $$ = new IntegerExpr(currentFile, yylineno, $1); 877 } 878 | string_literal_plus { 879 $$ = new StringExpr(currentFile, yylineno, $1); 880 } 881 | wide_string_literal_plus { 882 $$ = new WStringExpr(currentFile, yylineno, $1); 883 } 884 | CHARACTER_LITERAL { 885 $$ = new CharExpr(currentFile, yylineno, $1); 886 } 887 | WIDE_CHARACTER_LITERAL { 888 $$ = new WCharExpr(currentFile, yylineno, $1); 889 } 890 | FIXED_PT_LITERAL { 891 $$ = new FixedExpr(currentFile, yylineno, $1); 892 } 893 | FLOATING_PT_LITERAL { 894 $$ = new FloatExpr(currentFile, yylineno, $1); 895 } 896 | boolean_literal { 897 $$ = new BooleanExpr(currentFile, yylineno, $1); 898 } 899 ; 900 901string_literal_plus: 902 STRING_LITERAL { $$ = $1; } 903 | string_literal_plus STRING_LITERAL { 904 $$ = new char [strlen($1) + strlen($2) + 1]; 905 strcpy($$, $1); 906 strcat($$, $2); 907 delete [] $1; 908 delete [] $2; 909 } 910 ; 911 912wide_string_literal_plus: 913 WIDE_STRING_LITERAL { $$ = $1; } 914 | wide_string_literal_plus WIDE_STRING_LITERAL { 915 $$ = new IDL_WChar [idl_wstrlen($1) + idl_wstrlen($2) + 1]; 916 idl_wstrcpy($$, $1); 917 idl_wstrcat($$, $2); 918 delete [] $1; 919 delete [] $2; 920 } 921 ; 922 923boolean_literal: 924 TRUE_ { $$ = 1; } 925 | FALSE_ { $$ = 0; } 926 ; 927 928positive_int_const: 929 const_exp { 930 IdlLongVal v = $1->evalAsLongV(); 931 if (v.negative || v.u == 0) 932 IdlError(currentFile, yylineno, "Size must be at least 1"); 933 $$ = v.u; 934 } 935 ; 936 937type_dcl: 938 TYPEDEF type_declarator { $$ = $2; } 939 | struct_type { $$ = $1; } 940 | union_type { $$ = $1; } 941 | enum_type { $$ = $1; } 942 | NATIVE IDENTIFIER { 943 $$ = new Native(currentFile, yylineno, mainFile, $2); 944 } 945 | constr_forward_decl { $$ = $1; } 946 ; 947 948type_declarator: 949 type_spec declarators { 950 $$ = new Typedef(currentFile, yylineno, mainFile, 951 $1->type(), $1->constr(), $2); 952 delete $1; 953 } 954 ; 955 956type_spec: 957 simple_type_spec { $$ = new TypeSpec($1, 0); } 958 | constr_type_spec { $$ = new TypeSpec($1, 1); } 959 ; 960 961simple_type_spec: 962 base_type_spec { $$ = $1; } 963 | template_type_spec { $$ = $1; } 964 | scoped_name { 965 $$ = IdlType::scopedNameToType(currentFile, yylineno, $1); 966 } 967 ; 968 969base_type_spec: 970 floating_pt_type { $$ = $1; } 971 | integer_type { $$ = $1; } 972 | char_type { $$ = $1; } 973 | wide_char_type { $$ = $1; } 974 | boolean_type { $$ = $1; } 975 | octet_type { $$ = $1; } 976 | any_type { $$ = $1; } 977 | object_type { $$ = $1; } 978 | value_base_type { $$ = $1; } 979 ; 980 981template_type_spec: 982 sequence_type { $$ = $1; } 983 | string_type { $$ = $1; } 984 | wide_string_type { $$ = $1; } 985 | fixed_pt_type { $$ = $1; } 986 ; 987 988constr_type_spec: 989 struct_type { $$ = $1->thisType(); } 990 | union_type { $$ = $1->thisType(); } 991 | enum_type { $$ = $1->thisType(); } 992 ; 993 994declarators: 995 declarator pragmas_opt { $$ = $1; } 996 | declarators ',' pragmas_opt declarator pragmas_opt { 997 if ($1) { $1->append($4); $$ = $1; } 998 else $$ = $4; 999 } 1000 ; 1001 1002declarator: 1003 simple_declarator { $$ = $1; } 1004 | complex_declarator { $$ = $1; } 1005 ; 1006 1007simple_declarator: 1008 IDENTIFIER { 1009 $$ = new Declarator(currentFile, yylineno, mainFile, $1, 0); 1010 } 1011 ; 1012 1013complex_declarator: 1014 array_declarator { $$ = $1; } 1015 ; 1016 1017floating_pt_type: 1018 FLOAT { $$ = BaseType::floatType; } 1019 | DOUBLE { $$ = BaseType::doubleType; } 1020 | LONG DOUBLE { $$ = BaseType::longdoubleType; } 1021 ; 1022 1023integer_type: 1024 signed_int { $$ = $1; } 1025 | unsigned_int { $$ = $1; } 1026 ; 1027 1028signed_int: 1029 signed_short_int { $$ = $1; } 1030 | signed_long_int { $$ = $1; } 1031 | signed_long_long_int { $$ = $1; } 1032 ; 1033 1034signed_short_int: 1035 SHORT { $$ = BaseType::shortType; } 1036 ; 1037 1038signed_long_int: 1039 LONG { $$ = BaseType::longType; } 1040 ; 1041 1042signed_long_long_int: 1043 LONG LONG { $$ = BaseType::longlongType; } 1044 ; 1045 1046unsigned_int: 1047 unsigned_short_int { $$ = $1; } 1048 | unsigned_long_int { $$ = $1; } 1049 | unsigned_long_long_int { $$ = $1; } 1050 ; 1051 1052unsigned_short_int: 1053 UNSIGNED SHORT { $$ = BaseType::ushortType; } 1054 ; 1055 1056unsigned_long_int: 1057 UNSIGNED LONG { $$ = BaseType::ulongType; } 1058 ; 1059 1060unsigned_long_long_int: 1061 UNSIGNED LONG LONG { $$ = BaseType::ulonglongType; } 1062 ; 1063 1064char_type: 1065 CHAR { $$ = BaseType::charType; } 1066 ; 1067 1068wide_char_type: 1069 WCHAR { $$ = BaseType::wcharType; } 1070 ; 1071 1072boolean_type: 1073 BOOLEAN { $$ = BaseType::booleanType; } 1074 ; 1075 1076octet_type: 1077 OCTET { $$ = BaseType::octetType; } 1078 ; 1079 1080any_type: 1081 ANY { $$ = BaseType::anyType; } 1082 ; 1083 1084object_type: 1085 OBJECT { $$ = DeclaredType::corbaObjectType; } 1086 ; 1087 1088struct_type: 1089 struct_header pragmas_opt '{' pragmas_opt member_list '}' { 1090 $1->finishConstruction($5); 1091 $$ = $1; 1092 } 1093 | struct_header error { 1094 IdlSyntaxError(currentFile, yylineno, 1095 "Syntax error in struct definition"); 1096 $1->finishConstruction(0); 1097 $$ = $1; 1098 } 1099 ; 1100 1101struct_header: 1102 STRUCT IDENTIFIER { 1103 $$ = new Struct(currentFile, yylineno, mainFile, $2); 1104 } 1105 ; 1106 1107member_list: 1108 member pragmas_opt { $$ = $1; } 1109 | member_list member pragmas_opt { 1110 if ($1) { $1->append($2); $$ = $1; } 1111 else $$ = $2; 1112 } 1113 ; 1114 1115member: 1116 type_spec declarators ';' { 1117 $$ = new Member(currentFile, yylineno, mainFile, 1118 $1->type(), $1->constr(), $2); 1119 delete $1; 1120 } 1121 | error { 1122 IdlSyntaxError(currentFile, yylineno, 1123 "Syntax error in member declaration"); 1124 $$ = 0; 1125 } 1126 ; 1127 1128union_type: 1129 union_header pragmas_opt SWITCH 1130 '(' pragmas_opt switch_type_spec pragmas_opt ')' 1131 pragmas_opt '{' pragmas_opt switch_body '}' { 1132 1133 $1->finishConstruction($6->type(), $6->constr(), $12); 1134 delete $6; 1135 $$ = $1; 1136 } 1137 | union_header error { 1138 IdlSyntaxError(currentFile, yylineno, 1139 "Syntax error in union declaration"); 1140 $1->finishConstruction(0, 0, 0); 1141 $$ = $1; 1142 } 1143 ; 1144 1145union_header: 1146 UNION IDENTIFIER { 1147 $$ = new Union(currentFile, yylineno, mainFile, $2); 1148 } 1149 ; 1150 1151switch_type_spec: 1152 integer_type { $$ = new TypeSpec($1, 0); } 1153 | char_type { $$ = new TypeSpec($1, 0); } 1154 | boolean_type { $$ = new TypeSpec($1, 0); } 1155 | enum_type { $$ = new TypeSpec($1->thisType(), 1); } 1156 | scoped_name { 1157 $$ = new TypeSpec(IdlType::scopedNameToType(currentFile, yylineno, $1), 1158 0); 1159 } 1160 ; 1161 1162switch_body: 1163 case_plus { $$ = $1; } 1164 ; 1165 1166case_plus: 1167 case pragmas_opt { $$ = $1; } 1168 | case_plus case pragmas_opt { 1169 $1->append($2); 1170 $$ = $1; 1171 } 1172 ; 1173 1174case: 1175 case_label_plus element_spec ';' { 1176 $2->finishConstruction($1); 1177 $$ = $2; 1178 } 1179 ; 1180 1181case_label_plus: 1182 case_label { $$ = $1; } 1183 | case_label_plus case_label { 1184 $1->append($2); 1185 $$ = $1; 1186 } 1187 ; 1188 1189case_label: 1190 CASE const_exp ':' pragmas_opt { 1191 $$ = new CaseLabel(currentFile, yylineno, mainFile, $2); 1192 } 1193 | DEFAULT ':' pragmas_opt { 1194 $$ = new CaseLabel(currentFile, yylineno, mainFile, 0); 1195 } 1196 ; 1197 1198element_spec: 1199 type_spec declarator { 1200 $$ = new UnionCase(currentFile, yylineno, mainFile, 1201 $1->type(), $1->constr(), $2); 1202 } 1203 ; 1204 1205enum_type: 1206 enum_header pragmas_opt '{' pragmas_opt enumerator_list '}' { 1207 $1->finishConstruction($5); 1208 $$ = $1; 1209 } 1210 | enum_header error { 1211 IdlSyntaxError(currentFile, yylineno, "Syntax error in enum definition"); 1212 $1->finishConstruction(0); 1213 $$ = $1; 1214 } 1215 ; 1216 1217enum_header: 1218 ENUM IDENTIFIER { 1219 $$ = new Enum(currentFile, yylineno, mainFile, $2); 1220 } 1221 ; 1222 1223enumerator_list: 1224 enumerator pragmas_opt { $$ = $1; } 1225 | enumerator_list ',' pragmas_opt enumerator pragmas_opt { 1226 $1->append($4); 1227 $$ = $1; 1228 } 1229 ; 1230 1231enumerator: 1232 IDENTIFIER { 1233 $$ = new Enumerator(currentFile, yylineno, mainFile, $1); 1234 } 1235 ; 1236 1237sequence_type: 1238 SEQUENCE '<' simple_type_spec ',' positive_int_const '>' { 1239 $$ = new SequenceType($3, $5); 1240 } 1241 | SEQUENCE '<' simple_type_spec '>' { 1242 $$ = new SequenceType($3, 0); 1243 } 1244 ; 1245 1246string_type: 1247 STRING '<' positive_int_const '>' { $$ = new StringType($3); } 1248 | STRING { 1249 $$ = StringType::unboundedStringType; 1250 } 1251 ; 1252 1253wide_string_type: 1254 WSTRING '<' positive_int_const '>' { $$ = new WStringType($3); } 1255 | WSTRING { 1256 $$ = WStringType::unboundedWStringType; 1257 } 1258 ; 1259 1260array_declarator: 1261 IDENTIFIER fixed_array_size_plus { 1262 $$ = new Declarator(currentFile, yylineno, mainFile, $1, $2); 1263 } 1264 ; 1265 1266fixed_array_size_plus: 1267 fixed_array_size { $$ = $1; } 1268 | fixed_array_size_plus fixed_array_size { 1269 $1->append($2); 1270 $$ = $1; 1271 } 1272 ; 1273 1274fixed_array_size: 1275 '[' positive_int_const ']' { $$ = new ArraySize($2); } 1276 ; 1277 1278attr_dcl: 1279 readonly_opt ATTRIBUTE param_type_spec simple_declarator_list { 1280 $$ = new Attribute(currentFile, yylineno, mainFile, $1, $3, $4); 1281 } 1282 ; 1283 1284readonly_opt: 1285 /* empty */ { $$ = 0; } 1286 | READONLY { $$ = 1; } 1287 ; 1288 1289simple_declarator_list: 1290 simple_declarator pragmas_opt { $$ = $1; } 1291 | simple_declarator_list ',' pragmas_opt simple_declarator pragmas_opt { 1292 if ($1) { $1->append($4); $$ = $1; } 1293 else $$ = $4; 1294 } 1295 ; 1296 1297except_dcl: 1298 except_header pragmas_opt '{' pragmas_opt member_star '}' { 1299 $1->finishConstruction($5); 1300 $$ = $1; 1301 } 1302 | except_header error { 1303 IdlSyntaxError(currentFile, yylineno, 1304 "Syntax error in exception definition"); 1305 $1->finishConstruction(0); 1306 $$ = $1; 1307 } 1308 ; 1309 1310except_header: 1311 EXCEPTION IDENTIFIER { 1312 $$ = new Exception(currentFile, yylineno, mainFile, $2); 1313 } 1314 ; 1315 1316member_star: 1317 /* empty */ { $$ = 0; } 1318 | member_star member { 1319 if ($1) { $1->append($2); $$ = $1; } 1320 else $$ = $2; 1321 } 1322 ; 1323 1324op_dcl: 1325 op_header pragmas_opt parameter_dcls { 1326 $1->closeParens(); 1327 } pragmas_opt raises_expr_opt context_expr_opt { 1328 $1->finishConstruction($3, $6, $7); 1329 $$ = $1; 1330 } 1331 | op_header error { 1332 IdlSyntaxError(currentFile, yylineno, 1333 "Syntax error in operation declaration"); 1334 $1->closeParens(); 1335 $1->finishConstruction(0, 0, 0); 1336 $$ = $1; 1337 } 1338 ; 1339 1340op_header: 1341 op_attribute_opt op_type_spec IDENTIFIER { 1342 $$ = new Operation(currentFile, yylineno, mainFile, $1, $2, $3); 1343 } 1344 ; 1345 1346op_attribute_opt: 1347 /* empty */ { $$ = 0; } 1348 | op_attribute { $$ = $1; } 1349 ; 1350 1351op_attribute: 1352 ONEWAY { $$ = 1; } 1353 ; 1354 1355op_type_spec: 1356 param_type_spec { $$ = $1; } 1357 | VOID { $$ = BaseType::voidType; } 1358 ; 1359 1360parameter_dcls: 1361 '(' pragmas_opt param_dcl_list ')' { $$ = $3; } 1362 | '(' pragmas_opt ')' { $$ = 0; } 1363 | '(' error ')' { 1364 IdlSyntaxError(currentFile, yylineno, 1365 "Syntax error in operation parameters"); 1366 $$ = 0; 1367 } 1368 ; 1369 1370param_dcl_list: 1371 param_dcl pragmas_opt { $$ = $1; } 1372 | param_dcl_list ',' pragmas_opt param_dcl pragmas_opt { 1373 if ($1) { $1->append($4); $$ = $1; } 1374 else $$ = $4; 1375 } 1376 ; 1377 1378param_dcl: 1379 param_attribute param_type_spec IDENTIFIER { 1380 $$ = new Parameter(currentFile, yylineno, mainFile, $1, $2, $3); 1381 } 1382 ; 1383 1384param_attribute: 1385 IN { $$ = 0; } 1386 | OUT { $$ = 1; } 1387 | INOUT { $$ = 2; } 1388 ; 1389 1390raises_expr_opt: 1391 /* empty */ { $$ = 0; } 1392 | raises_expr pragmas_opt { $$ = $1; } 1393 ; 1394 1395raises_expr: 1396 RAISES '(' scoped_name_list ')' { $$ = $3; } 1397 ; 1398 1399scoped_name_list: 1400 scoped_name pragmas_opt { 1401 $$ = new RaisesSpec($1, currentFile, yylineno); 1402 } 1403 | scoped_name_list ',' pragmas_opt scoped_name pragmas_opt { 1404 $1->append(new RaisesSpec($4, currentFile, yylineno)); 1405 $$ = $1; 1406 } 1407 ; 1408 1409context_expr_opt: 1410 /* empty */ { $$ = 0; } 1411 | context_expr pragmas_opt { $$ = $1; } 1412 ; 1413 1414context_expr: 1415 CONTEXT '(' string_literal_list ')' { $$ = $3; } 1416 ; 1417 1418string_literal_list: 1419 string_literal_plus pragmas_opt { 1420 $$ = new ContextSpec($1, currentFile, yylineno); 1421 } 1422 | string_literal_list ',' pragmas_opt string_literal_plus pragmas_opt { 1423 $1->append(new ContextSpec($4, currentFile, yylineno)); 1424 $$ = $1; 1425 } 1426 ; 1427 1428param_type_spec: 1429 base_type_spec { $$ = $1; } 1430 | string_type { $$ = $1; } 1431 | wide_string_type { $$ = $1; } 1432 | scoped_name { 1433 $$ = IdlType::scopedNameToType(currentFile, yylineno, $1); 1434 } 1435 ; 1436 1437fixed_pt_type: 1438 FIXED '<' positive_int_const ',' const_exp '>' { 1439 IdlLongVal scalev = $5->evalAsLongV(); 1440 1441 if (scalev.negative) { 1442 IdlError(currentFile, yylineno, 1443 "Fixed point scale must be >= 0"); 1444 } 1445 IDL_ULong scale = scalev.u; 1446 1447 if ($3 > 31) { 1448 IdlError(currentFile, yylineno, 1449 "Fixed point values may not have more than 31 digits"); 1450 } 1451 if (scale > $3) { 1452 IdlError(currentFile, yylineno, 1453 "Fixed point scale factor is greater than " 1454 "the number of digits"); 1455 } 1456 $$ = new FixedType($3, scale); 1457 } 1458 ; 1459 1460fixed_pt_const_type: 1461 FIXED { 1462 $$ = new FixedType(0, 0); 1463 } 1464 ; 1465 1466value_base_type: 1467 VALUEBASE { $$ = new DeclaredType(IdlType::tk_value, 0, 0); } 1468 ; 1469 1470constr_forward_decl: 1471 STRUCT IDENTIFIER { 1472 $$ = new StructForward(currentFile, yylineno, mainFile, $2); 1473 } 1474 | UNION IDENTIFIER { 1475 $$ = new UnionForward(currentFile, yylineno, mainFile, $2); 1476 } 1477 ; 1478 1479pragma: 1480 pragma_id 1481 | pragma_version 1482 | unknown_pragma 1483 | omni_pragma 1484 ; 1485 1486pragmas: 1487 pragma 1488 | pragmas pragma 1489 ; 1490 1491pragmas_opt: 1492 /* empty */ 1493 | pragmas 1494 ; 1495 1496pragma_prefix: 1497 PRAGMA_PREFIX string_l