cppBisonDefs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file cppBisonDefs.h
  10. * @author drose
  11. * @date 1999-01-17
  12. */
  13. #ifndef CPPBISON_H
  14. #define CPPBISON_H
  15. // This header file defines the interface to the yacc (actually, bison) parser
  16. // and grammar. None of these interfaces are intended to be used directly;
  17. // they're defined here strictly to be used by the CPPParser and
  18. // CPPExpressionParser classes.
  19. #include "dtoolbase.h"
  20. #include <string>
  21. #include "cppClosureType.h"
  22. #include "cppExtensionType.h"
  23. #include "cppFile.h"
  24. class CPPParser;
  25. class CPPExpression;
  26. class CPPPreprocessor;
  27. class CPPDeclaration;
  28. class CPPInstance;
  29. class CPPType;
  30. class CPPStructType;
  31. class CPPEnumType;
  32. class CPPSimpleType;
  33. class CPPInstanceIdentifier;
  34. class CPPParameterList;
  35. class CPPTemplateParameterList;
  36. class CPPScope;
  37. class CPPIdentifier;
  38. class CPPCaptureType;
  39. void parse_cpp(CPPParser *cp);
  40. CPPExpression *parse_const_expr(CPPPreprocessor *pp,
  41. CPPScope *new_current_scope,
  42. CPPScope *new_global_scope);
  43. CPPType *parse_type(CPPPreprocessor *pp,
  44. CPPScope *new_current_scope,
  45. CPPScope *new_global_scope);
  46. extern CPPScope *current_scope;
  47. extern CPPScope *global_scope;
  48. extern CPPPreprocessor *current_lexer;
  49. // This structure holds the return value for each token. Traditionally, this
  50. // is a union, and is declared with the %union declaration in the parser.y
  51. // file, but unions are pretty worthless in C++ (you can't include an object
  52. // that has member functions in a union), so we'll use a class instead. That
  53. // means we need to declare it externally, here.
  54. class cppyystype {
  55. public:
  56. std::string str;
  57. union {
  58. unsigned long long integer;
  59. long double real;
  60. CPPScope *scope;
  61. CPPDeclaration *decl;
  62. CPPInstance *instance;
  63. CPPType *type;
  64. CPPStructType *struct_type;
  65. CPPEnumType *enum_type;
  66. CPPSimpleType *simple_type;
  67. CPPInstanceIdentifier *inst_ident;
  68. CPPParameterList *param_list;
  69. CPPTemplateParameterList *template_param_list;
  70. CPPExtensionType::Type extension_enum;
  71. CPPExpression *expr;
  72. CPPIdentifier *identifier;
  73. CPPClosureType *closure_type;
  74. CPPClosureType::Capture *capture;
  75. } u;
  76. };
  77. #define YYSTYPE cppyystype
  78. // This structure takes advantage of a bison feature to track the exact
  79. // location in the file of each token, for more useful error reporting. We
  80. // define it up here so we can reference it in the lexer.
  81. struct cppyyltype {
  82. // Bison expects these members to be part of this struct.
  83. int first_line;
  84. int first_column;
  85. int last_line;
  86. int last_column;
  87. // Early versions of bison (1.25 and earlier) expected these members to be
  88. // in this struct as well.
  89. int timestamp;
  90. char *text;
  91. // The remaining members are added for this application and have no meaning
  92. // to bison.
  93. CPPFile file;
  94. };
  95. #define YYLTYPE cppyyltype
  96. // Beginning around bison 1.35 or so, we need to define this macro as well, to
  97. // tell bison how to collect multiple locations together. (The default
  98. // implementation copies only first_line through last_column, whereas here we
  99. // use the struct assignment operator to copy all the members of the
  100. // structure).
  101. #define YYLLOC_DEFAULT(Current, Rhs, N) \
  102. (Current) = (Rhs)[1]; \
  103. (Current).last_line = (Rhs)[N].last_line; \
  104. (Current).last_column = (Rhs)[N].last_column;
  105. #endif