00001 // Filename: cppBisonDefs.h 00002 // Created by: drose (17Jan99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef CPPBISON_H 00020 #define CPPBISON_H 00021 00022 // This header file defines the interface to the yacc (actually, 00023 // bison) parser and grammar. None of these interfaces are intended 00024 // to be used directly; they're defined here strictly to be used by 00025 // the CPPParser and CPPExpressionParser classes. 00026 00027 #include <dtoolbase.h> 00028 00029 #include <string> 00030 00031 #include "cppExtensionType.h" 00032 #include "cppFile.h" 00033 00034 using namespace std; 00035 00036 class CPPParser; 00037 class CPPExpression; 00038 class CPPPreprocessor; 00039 class CPPDeclaration; 00040 class CPPInstance; 00041 class CPPType; 00042 class CPPStructType; 00043 class CPPEnumType; 00044 class CPPSimpleType; 00045 class CPPInstanceIdentifier; 00046 class CPPParameterList; 00047 class CPPTemplateParameterList; 00048 class CPPScope; 00049 class CPPIdentifier; 00050 00051 void parse_cpp(CPPParser *cp); 00052 CPPExpression *parse_const_expr(CPPPreprocessor *pp, 00053 CPPScope *new_current_scope, 00054 CPPScope *new_global_scope); 00055 CPPType *parse_type(CPPPreprocessor *pp, 00056 CPPScope *new_current_scope, 00057 CPPScope *new_global_scope); 00058 00059 extern CPPScope *current_scope; 00060 extern CPPScope *global_scope; 00061 extern CPPPreprocessor *current_lexer; 00062 00063 00064 // This structure holds the return value for each token. 00065 // Traditionally, this is a union, and is declared with the %union 00066 // declaration in the parser.y file, but unions are pretty worthless 00067 // in C++ (you can't include an object that has member functions in a 00068 // union), so we'll use a class instead. That means we need to 00069 // declare it externally, here. 00070 00071 class cppyystype { 00072 public: 00073 string str; 00074 union { 00075 int integer; 00076 double real; 00077 CPPScope *scope; 00078 CPPDeclaration *decl; 00079 CPPInstance *instance; 00080 CPPType *type; 00081 CPPStructType *struct_type; 00082 CPPEnumType *enum_type; 00083 CPPSimpleType *simple_type; 00084 CPPInstanceIdentifier *inst_ident; 00085 CPPParameterList *param_list; 00086 CPPTemplateParameterList *template_param_list; 00087 CPPExtensionType::Type extension_enum; 00088 CPPExpression *expr; 00089 CPPIdentifier *identifier; 00090 } u; 00091 }; 00092 #define YYSTYPE cppyystype 00093 00094 // This structure takes advantage of a bison feature to track the 00095 // exact location in the file of each token, for more useful error 00096 // reporting. We define it up here so we can reference it in the 00097 // lexer. 00098 00099 struct cppyyltype { 00100 // Bison expects these members to be part of this struct. 00101 int first_line; 00102 int first_column; 00103 int last_line; 00104 int last_column; 00105 00106 // Early versions of bison (1.25 and earlier) expected these members 00107 // to be in this struct as well. 00108 int timestamp; 00109 char *text; 00110 00111 // The remaining members are added for this application and have no 00112 // meaning to bison. 00113 CPPFile file; 00114 }; 00115 #define YYLTYPE cppyyltype 00116 00117 // Beginning around bison 1.35 or so, we need to define this macro as 00118 // well, to tell bison how to collect multiple locations together. 00119 // (The default implementation copies only first_line through 00120 // last_column, whereas here we use the struct assignment operator to 00121 // copy all the members of the structure). 00122 #define YYLLOC_DEFAULT(Current, Rhs, N) \ 00123 Current = Rhs[1]; \ 00124 Current.last_line = Rhs[N].last_line; \ 00125 Current.last_column = Rhs[N].last_column; 00126 00127 #endif