cppBisonDefs.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Filename: cppBisonDefs.h
  2. // Created by: drose (17Jan99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef CPPBISON_H
  19. #define CPPBISON_H
  20. // This header file defines the interface to the yacc (actually,
  21. // bison) parser and grammar. None of these interfaces are intended
  22. // to be used directly; they're defined here strictly to be used by
  23. // the CPPParser and CPPExpressionParser classes.
  24. #include <dtoolbase.h>
  25. #include <string>
  26. #include "cppExtensionType.h"
  27. #include "cppFile.h"
  28. using namespace std;
  29. class CPPParser;
  30. class CPPExpression;
  31. class CPPPreprocessor;
  32. class CPPDeclaration;
  33. class CPPInstance;
  34. class CPPType;
  35. class CPPStructType;
  36. class CPPEnumType;
  37. class CPPSimpleType;
  38. class CPPInstanceIdentifier;
  39. class CPPParameterList;
  40. class CPPTemplateParameterList;
  41. class CPPScope;
  42. class CPPIdentifier;
  43. void parse_cpp(CPPParser *cp);
  44. CPPExpression *parse_const_expr(CPPPreprocessor *pp,
  45. CPPScope *new_current_scope,
  46. CPPScope *new_global_scope);
  47. CPPType *parse_type(CPPPreprocessor *pp,
  48. CPPScope *new_current_scope,
  49. CPPScope *new_global_scope);
  50. extern CPPScope *current_scope;
  51. extern CPPScope *global_scope;
  52. extern CPPPreprocessor *current_lexer;
  53. // This structure holds the return value for each token.
  54. // Traditionally, this is a union, and is declared with the %union
  55. // declaration in the parser.y file, but unions are pretty worthless
  56. // in C++ (you can't include an object that has member functions in a
  57. // union), so we'll use a class instead. That means we need to
  58. // declare it externally, here.
  59. class yystype {
  60. public:
  61. string str;
  62. union {
  63. int integer;
  64. double real;
  65. CPPScope *scope;
  66. CPPDeclaration *decl;
  67. CPPInstance *instance;
  68. CPPType *type;
  69. CPPStructType *struct_type;
  70. CPPEnumType *enum_type;
  71. CPPSimpleType *simple_type;
  72. CPPInstanceIdentifier *inst_ident;
  73. CPPParameterList *param_list;
  74. CPPTemplateParameterList *template_param_list;
  75. CPPExtensionType::Type extension_enum;
  76. CPPExpression *expr;
  77. CPPIdentifier *identifier;
  78. } u;
  79. };
  80. #define YYSTYPE yystype
  81. // This structure takes advantage of a bison feature to track the
  82. // exact location in the file of each token, for more useful error
  83. // reporting. We define it up here so we can reference it in the
  84. // lexer.
  85. struct cppyyltype {
  86. int first_line;
  87. int first_column;
  88. int last_line;
  89. int last_column;
  90. CPPFile file;
  91. };
  92. #define YYLTYPE cppyyltype
  93. // Beginning around bison 1.35 or so, we need to define this macro as
  94. // well, to tell bison how to collect multiple locations together.
  95. #define YYLLOC_DEFAULT(Current, Rhs, N) \
  96. Current = Rhs[1]; \
  97. Current.last_line = Rhs[N].last_line; \
  98. Current.last_column = Rhs[N].last_column;
  99. #endif