cppParser.cxx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Filename: cppParser.cxx
  2. // Created by: drose (19Oct99)
  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. #include "cppParser.h"
  19. #include "cppFile.h"
  20. #include "cppTypeParser.h"
  21. #include "cppBisonDefs.h"
  22. #include <set>
  23. #include <assert.h>
  24. bool cppparser_output_class_keyword = true;
  25. ////////////////////////////////////////////////////////////////////
  26. // Function: CPPParser::Constructor
  27. // Access: Public
  28. // Description:
  29. ////////////////////////////////////////////////////////////////////
  30. CPPParser::
  31. CPPParser() : CPPScope((CPPScope *)NULL, CPPNameComponent(""), V_public) {
  32. }
  33. ////////////////////////////////////////////////////////////////////
  34. // Function: CPPParser::is_fully_specified
  35. // Access: Public, Virtual
  36. // Description: Returns true if this declaration is an actual,
  37. // factual declaration, or false if some part of the
  38. // declaration depends on a template parameter which has
  39. // not yet been instantiated.
  40. ////////////////////////////////////////////////////////////////////
  41. bool CPPParser::
  42. is_fully_specified() const {
  43. // The global scope is always considered to be "fully specified",
  44. // even if it contains some template declarations.
  45. return true;
  46. }
  47. ////////////////////////////////////////////////////////////////////
  48. // Function: CPPParser::parse_file
  49. // Access: Public
  50. // Description:
  51. ////////////////////////////////////////////////////////////////////
  52. bool CPPParser::
  53. parse_file(const string &filename) {
  54. if (!init_cpp(CPPFile(filename, filename, CPPFile::S_local))) {
  55. cerr << "Unable to read " << filename << "\n";
  56. return false;
  57. }
  58. parse_cpp(this);
  59. return get_error_count() == 0;
  60. }
  61. ////////////////////////////////////////////////////////////////////
  62. // Function: CPPParser::parse_expr
  63. // Access: Public
  64. // Description: Given a string, expand all manifests within the
  65. // string and evaluate it as an expression. Returns
  66. // NULL if the string is not a valid expression.
  67. ////////////////////////////////////////////////////////////////////
  68. CPPExpression *CPPParser::
  69. parse_expr(const string &expr) {
  70. return CPPPreprocessor::parse_expr(expr, this, this);
  71. }
  72. ////////////////////////////////////////////////////////////////////
  73. // Function: CPPParser::parse_type
  74. // Access: Public
  75. // Description: Given a string, interpret it as a type name and
  76. // return the corresponding CPPType. Returns NULL if
  77. // the string is not a valid type.
  78. ////////////////////////////////////////////////////////////////////
  79. CPPType *CPPParser::
  80. parse_type(const string &type) {
  81. CPPTypeParser ep(this, this);
  82. ep._verbose = 0;
  83. if (ep.parse_type(type, *this)) {
  84. return ep._type;
  85. } else {
  86. return (CPPType *)NULL;
  87. }
  88. }