00001 // Filename: cppParser.cxx 00002 // Created by: drose (19Oct99) 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 00020 #include "cppParser.h" 00021 #include "cppFile.h" 00022 #include "cppTypeParser.h" 00023 #include "cppBisonDefs.h" 00024 00025 #include <set> 00026 #include <assert.h> 00027 00028 bool cppparser_output_class_keyword = true; 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: CPPParser::Constructor 00032 // Access: Public 00033 // Description: 00034 //////////////////////////////////////////////////////////////////// 00035 CPPParser:: 00036 CPPParser() : CPPScope((CPPScope *)NULL, CPPNameComponent(""), V_public) { 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: CPPParser::is_fully_specified 00041 // Access: Public, Virtual 00042 // Description: Returns true if this declaration is an actual, 00043 // factual declaration, or false if some part of the 00044 // declaration depends on a template parameter which has 00045 // not yet been instantiated. 00046 //////////////////////////////////////////////////////////////////// 00047 bool CPPParser:: 00048 is_fully_specified() const { 00049 // The global scope is always considered to be "fully specified", 00050 // even if it contains some template declarations. 00051 return true; 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: CPPParser::parse_file 00056 // Access: Public 00057 // Description: 00058 //////////////////////////////////////////////////////////////////// 00059 bool CPPParser:: 00060 parse_file(const string &filename) { 00061 if (!init_cpp(CPPFile(filename, filename, CPPFile::S_local))) { 00062 cerr << "Unable to read " << filename << "\n"; 00063 return false; 00064 } 00065 parse_cpp(this); 00066 00067 return get_error_count() == 0; 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: CPPParser::parse_expr 00072 // Access: Public 00073 // Description: Given a string, expand all manifests within the 00074 // string and evaluate it as an expression. Returns 00075 // NULL if the string is not a valid expression. 00076 //////////////////////////////////////////////////////////////////// 00077 CPPExpression *CPPParser:: 00078 parse_expr(const string &expr) { 00079 return CPPPreprocessor::parse_expr(expr, this, this); 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: CPPParser::parse_type 00084 // Access: Public 00085 // Description: Given a string, interpret it as a type name and 00086 // return the corresponding CPPType. Returns NULL if 00087 // the string is not a valid type. 00088 //////////////////////////////////////////////////////////////////// 00089 CPPType *CPPParser:: 00090 parse_type(const string &type) { 00091 CPPTypeParser ep(this, this); 00092 ep._verbose = 0; 00093 if (ep.parse_type(type, *this)) { 00094 return ep._type; 00095 } else { 00096 return (CPPType *)NULL; 00097 } 00098 }