(file) Return to parser.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Compiler

  1 martin 1.25 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.26 //
  3 martin 1.25 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.26 //
 10 martin 1.25 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.26 //
 17 martin 1.25 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.26 //
 20 martin 1.25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.26 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.26 //
 28 martin 1.25 //////////////////////////////////////////////////////////////////////////
 29 mike   1.9  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32 jim.wunderlich 1.20 // bug 4573 - cimmof include file search path processing is inadequate
 33                     //
 34                     // Bug 4573 changed the behavior of the processing for locating specified
 35 karl           1.23 //  include files. The new procssing is based on the include file processing
 36 jim.wunderlich 1.20 //  behaviour used by the C compiler.
 37                     //
 38                     //      The search path for included files previously was:
 39                     //          1. try to open the file in the current working directory.
 40                     //          2. process the include path array from the cimof(l) cmdline
 41                     //             processing which always include "dot" as a default search
 42 karl           1.23 //             path and then any paths specified on the command line
 43 jim.wunderlich 1.20 //             with the -I option.
 44                     //
 45                     //      The search path for included files now is:
 46                     //          1. try to open the file in the same directory as the current
 47                     //             file being processed.
 48                     //          2. process the include path array from the cimof(l) cmdline
 49 karl           1.23 //             processing which only includes paths specified on the
 50 jim.wunderlich 1.20 //             command line with the -I option.
 51                     //
 52 mike           1.9  
 53                     //
 54 karl           1.23 // implementation of valueFactory
 55 mike           1.9  //
 56                     //
 57                     //
 58                     // implementation of those methods  of class parser which are not pure
 59                     // virtual
 60                     //
 61                     
 62                     #include "parser.h"
 63                     //#include <sstream>
 64                     #include "parserExceptions.h"
 65                     
 66 karl           1.27 
 67                     //-----------------------------------------------------------------------
 68                     //Implementation of the parserTypeFunctions
 69                     //-----------------------------------------------------------------------
 70                     static const char* _parserTypeStrings[] =
 71                     {
 72                        "Null","Integer", "Real", "String", "Boolean,", "Char"
 73                     };
 74                     
 75                     static const Uint32 _NUM_TYPES = sizeof(_parserTypeStrings) /
 76                                                     sizeof(_parserTypeStrings[0]);
 77                     
 78                     const char* strValTypeEnumToString(strValTypeNS::strValTypeEnum type)
 79                     {
 80 ashok.pathak   1.28     PEGASUS_ASSERT(Uint32(type) < _NUM_TYPES);
 81 karl           1.27     return _parserTypeStrings[Uint32(type)];
 82                     
 83                     }
 84 mike           1.9  //---------------------------------------------------------------------
 85                     // Take a YY_BUFFERSTATE off the stack of saved contexts
 86                     //---------------------------------------------------------------------
 87                     bufstate *
 88 karl           1.23 parser::pop_statebuff()
 89                     {
 90 mike           1.9      bufstate *v = 0;
 91 karl           1.23     if (!_include_stack.isEmpty())
 92                         {
 93                             v = _include_stack.top();
 94                             _include_stack.pop();
 95 mike           1.9      }
 96                         return v;
 97                     }
 98                     
 99                     //-------------------------------------------------------------------
100                     // Create a flex input buffer from a String containing the file name
101                     //-------------------------------------------------------------------
102 karl           1.23 int parser::setInputBufferFromName(const String &filename)
103                     {
104 ouyang.jian    1.22 #if defined (PEGASUS_OS_VMS)
105 karl           1.23     FILE *f = fopen(filename.getCString(),"r");
106 chuck          1.13 #else
107 karl           1.23     FILE *f = fopen(filename.getCString(),"rt");
108 chuck          1.13 #endif
109 karl           1.27     if (f)
110                         {
111 karl           1.23         set_current_filename(filename);
112                             set_lineno(1);
113                             return setInputBuffer(f, false);
114 karl           1.27     } else
115                         {
116 karl           1.23         return 1;
117                         }
118 mike           1.9  }
119                     
120                     //-----------------------------------------------------------------
121                     // Handle the end of an input buffer.  Either there is saved context
122                     // or there isn't.  If there is, restore the saved particulars
123                     // of that context so we can keep on parsing
124                     //-----------------------------------------------------------------
125 karl           1.23 int parser::wrap()
126                     {
127                         bufstate *v = pop_statebuff();
128                         if (v)
129                         {
130                             setInputBuffer(v->buffer_state, true);
131                             set_current_filename(v->filename);
132                             set_lineno(v->lineno);
133                             set_current_filenamePath(v->filenamePath);
134                             delete v;
135                             return 0;  // more data available
136 karl           1.27     } else
137                         {
138 karl           1.23         return 1;  // end of it all
139                         }
140 mike           1.9  }
141                     
142                     #ifdef PEGASUS_HAVE_NAMESPACES
143                     using namespace ParserExceptions;
144                     #endif /* PEGASUS_HAVE_NAMESPACES */
145                     
146                     //----------------------------------------------------------------
147 karl           1.10 // ATTN: P2 BB 2001 Log where an error occured.  This is lame, so it needs work
148 karl           1.23 //
149 mike           1.9  //----------------------------------------------------------------
150 karl           1.23 void parser::log_parse_error(char *token, const char *errmsg) const
151                     {
152                         char buf[40];
153 kumpf          1.24     sprintf(buf, "%u", _lineno);
154 karl           1.23     String s = _current_filename + ":" + buf + ": " + errmsg + " before `"
155                             + token + "'\n";
156                         throw ParserLexException(s);
157 mike           1.9  }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2