idl.yy
来自「编译工具」· YY 代码 · 共 1,543 行 · 第 1/3 页
YY
1,543 行
// -*- c++ -*-// Package : omniidl// idl.yy Created on: 1999/10/05// Author : Duncan Grisby (dpg1)//// Copyright (C) 1999 AT&T Laboratories Cambridge//// This file is part of omniidl.//// omniidl is free software; you can redistribute it and/or modify it// under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA// 02111-1307, USA.//// Description:// // Bison parser// $Id: idl.yy,v 1.11.2.7 2001/08/29 11:54:19 dpg1 Exp $// $Log: idl.yy,v $// Revision 1.11.2.7 2001/08/29 11:54:19 dpg1// Clean up const handling in IDL compiler.//// Revision 1.11.2.6 2001/03/13 10:32:10 dpg1// Fixed point support.//// Revision 1.11.2.5 2000/12/05 17:45:18 dpg1// omniidl case sensitivity updates from omni3_develop.//// Revision 1.11.2.4 2000/11/01 12:45:55 dpg1// Update to CORBA 2.4 specification.//// Revision 1.11.2.3 2000/10/27 16:31:07 dpg1// Clean up of omniidl dependencies and types, from omni3_develop.//// Revision 1.11.2.2 2000/10/10 10:18:50 dpg1// Update omniidl front-end from omni3_develop.//// Revision 1.9.2.5 2000/08/01 11:27:45 dpg1// Comments were incorrectly attached to struct members.//// Revision 1.9.2.4 2000/06/09 11:20:47 dpg1// Last fix put __omni_pragma line numbers off by one...//// Revision 1.9.2.3 2000/06/08 14:58:19 dpg1// Line numbers for #pragmas and // comments were off by one//// Revision 1.9.2.2 2000/06/08 14:36:19 dpg1// Comments and pragmas are now objects rather than plain strings, so// they can have file,line associated with them.//// Revision 1.9.2.1 2000/06/05 18:13:26 dpg1// Comments can be attached to subsequent declarations (with -K). Better// idea of most recent decl in operation declarations//// Revision 1.9 2000/02/04 12:17:09 dpg1// Support for VMS.//// Revision 1.8 1999/12/28 18:16:07 dpg1// positive_int_const isn't allowed to be zero.//// Revision 1.7 1999/11/17 17:17:00 dpg1// Changes to remove static initialisation of objects.//// Revision 1.6 1999/11/04 17:16:55 dpg1// Changes for NT.//// Revision 1.5 1999/11/03 17:24:05 dpg1// Added optional pragmas all over the place.//// Revision 1.4 1999/11/02 17:07:28 dpg1// Changes to compile on Solaris.//// Revision 1.3 1999/11/01 20:19:57 dpg1// Support for union switch types declared inside the switch statement.//// Revision 1.2 1999/10/29 15:41:31 dpg1// DeclaredType() now takes extra DeclRepoId* argument.//// Revision 1.1 1999/10/27 14:06:00 dpg1// *** empty log message ***//%{#include <stdlib.h>#include <string.h>#include <idlutil.h>#include <idlerr.h>#include <idlrepoId.h>#include <idlscope.h>#include <idltype.h>#include <idlexpr.h>#include <idlast.h>#define YYDEBUG 1// Globals from lexerextern int yylineno;extern char* currentFile;extern IDL_Boolean mainFile;void yyerror(char *s) {}extern int yylex();// Nasty hack for abstract valuetypesValueAbs* valueabs_hack = 0;#ifdef __VMS/* Apparently, __ALLOCA is defined for some versions of the C (but not C++) compiler on VAX. */#if defined(__ALPHA) || defined(__DECC) && __DECC_VER >= 60000000#include <builtins.h>#define alloca __ALLOCA#else#define alloca malloc#endif#endif%}%union { char* id_val; int int_val; IDL_ULong ulong_val; IdlIntLiteral int_literal_val;#ifndef __VMS IdlFloatLiteral float_literal_val;#else double float_literal_val;#endif char char_val; char* string_val; IDL_WChar wchar_val; IDL_WChar* wstring_val; IDL_Boolean boolean_val; IDL_Fixed* fixed_val; IdlType* type_val; TypeSpec* type_spec_val; IdlExpr* expr_val; ScopedName* scopedname_val; Decl* decl_val; Module* module_val; Interface* interface_val; InheritSpec* inheritspec_val; Forward* forward_val; Const* const_val; Typedef* typedef_val; Struct* struct_val; Exception* exception_val; Member* member_val; Declarator* declarator_val; Union* union_val; UnionCase* union_case_val; CaseLabel* case_label_val; ValueBase* value_base_val; Value* value_val; ValueForward* value_forward_val; ValueBox* value_box_val; ValueAbs* value_abs_val; ValueInheritSpec* valueinheritspec_val; ValueInheritSupportSpec* valueinheritsupportspec_val; StateMember* statemember_val; Factory* factory_val; Enumerator* enumerator_val; Enum* enum_val; ArraySize* array_size_val; Attribute* attribute_val; Operation* operation_val; Parameter* parameter_val; RaisesSpec* raisesspec_val; ContextSpec* contextspec_val;}%token <id_val> IDENTIFIER// Keywords%token ABSTRACT%token ANY%token ATTRIBUTE%token BOOLEAN%token CASE%token CHAR%token CONST%token CONTEXT%token CUSTOM%token DEFAULT%token DOUBLE%token ENUM%token EXCEPTION%token FACTORY%token FALSE_%token FIXED%token FLOAT%token IN%token INOUT%token INTERFACE%token LOCAL%token LONG%token MODULE%token NATIVE%token OBJECT%token OCTET%token ONEWAY%token OUT%token PRIVATE%token PUBLIC%token RAISES%token READONLY%token SEQUENCE%token SHORT%token STRING%token STRUCT%token SUPPORTS%token SWITCH%token TRUE_%token TRUNCATABLE%token TYPEDEF%token UNION%token UNSIGNED%token VALUEBASE%token VALUETYPE%token VOID%token WCHAR%token WSTRING// Pragmas%token PRAGMA%token PRAGMA_PREFIX%token PRAGMA_ID%token PRAGMA_VERSION%token OMNI_PRAGMA%token END_PRAGMA%token <string_val> UNKNOWN_PRAGMA_BODY// Literals%token <int_literal_val> INTEGER_LITERAL%token <char_val> CHARACTER_LITERAL%token <wchar_val> WIDE_CHARACTER_LITERAL%token <float_literal_val> FLOATING_PT_LITERAL%token <string_val> STRING_LITERAL%token <wstring_val> WIDE_STRING_LITERAL%token <fixed_val> FIXED_PT_LITERAL// Scope delimiter%token SCOPE_DELIM// Operators%token LEFT_SHIFT%token RIGHT_SHIFT// Types of nonterminals%type <decl_val> start%type <decl_val> definition_plus%type <decl_val> definition%type <module_val> module%type <module_val> module_header%type <decl_val> interface%type <interface_val> interface_dcl%type <forward_val> forward_dcl%type <interface_val> interface_header%type <decl_val> interface_body%type <decl_val> export_star%type <decl_val> export%type <inheritspec_val> interface_inheritance_spec_opt%type <inheritspec_val> interface_inheritance_spec%type <inheritspec_val> interface_inheritance_list%type <scopedname_val> interface_name%type <scopedname_val> scoped_name%type <value_base_val> value%type <value_forward_val> value_forward_dcl%type <int_val> abstract_local_opt%type <value_box_val> value_box_dcl%type <value_abs_val> value_abs_dcl%type <value_val> value_dcl%type <value_val> value_header%type <valueinheritsupportspec_val> value_inheritance_spec%type <valueinheritspec_val> value_value_inheritance_spec%type <boolean_val> truncatable_opt%type <valueinheritspec_val> value_inheritance_list%type <scopedname_val> value_name%type <decl_val> value_element_star%type <decl_val> value_element%type <statemember_val> state_member%type <ulong_val> member_access%type <factory_val> init_dcl%type <factory_val> init_dcl_header%type <parameter_val> init_param_decls_opt%type <parameter_val> init_param_decls%type <parameter_val> init_param_decl%type <const_val> const_dcl%type <type_val> const_type%type <expr_val> const_exp%type <expr_val> or_expr%type <expr_val> xor_expr%type <expr_val> and_expr%type <expr_val> shift_expr%type <expr_val> add_expr%type <expr_val> mult_expr%type <expr_val> unary_expr%type <char_val> unary_operator%type <expr_val> primary_expr%type <expr_val> literal%type <boolean_val> boolean_literal%type <string_val> string_literal_plus%type <wstring_val> wide_string_literal_plus%type <ulong_val> positive_int_const%type <decl_val> type_dcl%type <typedef_val> type_declarator%type <type_spec_val> type_spec%type <type_val> simple_type_spec%type <type_val> base_type_spec%type <type_val> template_type_spec%type <type_val> constr_type_spec%type <declarator_val> declarators%type <declarator_val> declarator%type <declarator_val> simple_declarator%type <declarator_val> complex_declarator%type <type_val> floating_pt_type%type <type_val> integer_type%type <type_val> signed_int%type <type_val> signed_short_int%type <type_val> signed_long_int%type <type_val> signed_long_long_int%type <type_val> unsigned_int%type <type_val> unsigned_short_int%type <type_val> unsigned_long_int%type <type_val> unsigned_long_long_int%type <type_val> char_type%type <type_val> wide_char_type%type <type_val> boolean_type%type <type_val> octet_type%type <type_val> any_type%type <type_val> object_type%type <struct_val> struct_type%type <struct_val> struct_header%type <member_val> member_list%type <member_val> member%type <union_val> union_type%type <union_val> union_header%type <type_spec_val> switch_type_spec%type <union_case_val> switch_body%type <union_case_val> case_plus%type <union_case_val> case%type <case_label_val> case_label_plus%type <case_label_val> case_label%type <union_case_val> element_spec%type <enum_val> enum_type%type <enum_val> enum_header%type <enumerator_val> enumerator_list%type <enumerator_val> enumerator%type <type_val> sequence_type%type <type_val> string_type%type <type_val> wide_string_type%type <declarator_val> array_declarator%type <array_size_val> fixed_array_size_plus%type <array_size_val> fixed_array_size%type <attribute_val> attr_dcl%type <boolean_val> readonly_opt%type <declarator_val> simple_declarator_list%type <exception_val> except_dcl%type <exception_val> except_header%type <member_val> member_star%type <operation_val> op_dcl%type <operation_val> op_header%type <boolean_val> op_attribute_opt%type <boolean_val> op_attribute%type <type_val> op_type_spec%type <parameter_val> parameter_dcls%type <parameter_val> param_dcl_list%type <parameter_val> param_dcl%type <int_val> param_attribute%type <raisesspec_val> raises_expr_opt%type <raisesspec_val> raises_expr%type <raisesspec_val> scoped_name_list%type <contextspec_val> context_expr_opt%type <contextspec_val> context_expr%type <contextspec_val> string_literal_list%type <type_val> param_type_spec%type <type_val> fixed_pt_type%type <type_val> fixed_pt_const_type%type <type_val> value_base_type%type <decl_val> constr_forward_decl%type <string_val> unknown_pragma_body_plus%%start: /* empty */ { $$ = 0; } | definition_plus { $$ = $1; AST::tree()->setDeclarations($1); } ;definition_plus: definition { $$ = $1; } | definition_plus definition { if ($1) { $1->append($2); $$ = $1; } else $$ = $2; } ;definition: type_dcl ';' { $$ = $1; } | const_dcl ';' { $$ = $1; } | except_dcl ';' { $$ = $1; } | interface ';' { $$ = $1; } | module ';' { $$ = $1; } | value ';' { $$ = $1; } | pragma { $$ = 0; } | pragma_prefix { $$ = 0; } | error { IdlSyntaxError(currentFile, yylineno, "Syntax error in definition"); $$ = 0; } ;module: module_header pragmas_opt '{' definition_plus '}' { $1->finishConstruction($4); $$ = $1; } | module_header error { IdlSyntaxError(currentFile, yylineno, "Syntax error in module definition"); } '{' definition_plus '}' { $1->finishConstruction($5); $$ = $1; } | module_header error { IdlSyntaxError(currentFile, yylineno, "Syntax error in module definition (no body found)"); $1->finishConstruction(0); $$ = $1; } ;module_header: MODULE IDENTIFIER { $$ = new Module(currentFile, yylineno, mainFile, $2); } ;interface: interface_dcl { $$ = $1; } | forward_dcl { $$ = $1; } ;interface_dcl: interface_header '{' interface_body '}' { $1->finishConstruction($3); $$ = $1; } | interface_header error { IdlSyntaxError(currentFile, yylineno, "Syntax error in interface definition"); } '{' interface_body '}' { $1->finishConstruction($5); $$ = $1; } | interface_header error { IdlSyntaxError(currentFile, yylineno, "Syntax error in interface definition (no body found)"); $1->finishConstruction(0); $$ = $1; } ;forward_dcl: abstract_local_opt INTERFACE IDENTIFIER { $$ = new Forward(currentFile, yylineno, mainFile, $3, $1==1, $1==2); } ;interface_header: abstract_local_opt INTERFACE IDENTIFIER pragmas_opt interface_inheritance_spec_opt { $$ = new Interface(currentFile, yylineno, mainFile, $3, $1==1, $1==2, $5); } ;abstract_local_opt: /* empty */ { $$ = 0; } | ABSTRACT { $$ = 1; } | LOCAL { $$ = 2; } ;interface_body: export_star { $$ = $1; } ;export_star: /* empty */ { $$ = 0; } | export_star export { if ($1) { $1->append($2); $$ = $1; } else $$ = $2; } ;export: type_dcl ';' { $$ = $1; } | const_dcl ';' { $$ = $1; } | except_dcl ';' { $$ = $1; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?