1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

STEP - support C++ streams for import / export

- New possibility to import STEP from stream.
- Update STEP low-level parser, using bison/flex generator from C to C++.

Add new method ReadStream(const Standard_CString filename, std::istream* istream) for all necessary classes to access main StepFile_Read() function with using stream.
This commit is contained in:
imn
2016-04-06 16:09:55 +03:00
committed by ika
parent d2c909178e
commit d38eddc38f
29 changed files with 4325 additions and 3862 deletions

View File

@@ -89,3 +89,12 @@ IFSelect_WorkLibrary::IFSelect_WorkLibrary () { thelevdef = 0; }
if (str.IsNull()) return ""; if (str.IsNull()) return "";
return str->ToCString(); return str->ToCString();
} }
Standard_Integer IFSelect_WorkLibrary::ReadStream(const Standard_CString /*name*/,
std::istream* /*istream*/,
Handle(Interface_InterfaceModel)& /*model*/,
const Handle(Interface_Protocol)& /*protocol*/) const
{
return 1;
}

View File

@@ -63,6 +63,15 @@ public:
//! and recognize the Entities) //! and recognize the Entities)
Standard_EXPORT virtual Standard_Integer ReadFile (const Standard_CString name, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const = 0; Standard_EXPORT virtual Standard_Integer ReadFile (const Standard_CString name, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const = 0;
//! Gives the way to Read a stream and transfer it to a Model
//! <mod> is the resulting Model, which has to be created by this
//! method. In case of error, <mod> must be returned Null
//! Return value is a status with free values.
//! Simply, 0 is for "Execution OK"
//! The Protocol can be used to work (e.g. create the Model, read
//! and recognize the Entities)
Standard_EXPORT virtual Standard_Integer ReadStream(const Standard_CString name, std::istream* istream, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const;
//! Gives the way to Write a File from a Model. //! Gives the way to Write a File from a Model.
//! <ctx> contains all necessary informations : the model, the //! <ctx> contains all necessary informations : the model, the
//! protocol, the file name, and the list of File Modifiers to be //! protocol, the file name, and the list of File Modifiers to be

View File

@@ -207,8 +207,7 @@ void IFSelect_WorkSession::SetModel
//purpose : //purpose :
//======================================================================= //=======================================================================
IFSelect_ReturnStatus IFSelect_WorkSession::ReadFile IFSelect_ReturnStatus IFSelect_WorkSession::ReadFile(const Standard_CString filename)
(const Standard_CString filename)
{ {
if (thelibrary.IsNull()) return IFSelect_RetVoid; if (thelibrary.IsNull()) return IFSelect_RetVoid;
if (theprotocol.IsNull()) return IFSelect_RetVoid; if (theprotocol.IsNull()) return IFSelect_RetVoid;
@@ -216,7 +215,7 @@ IFSelect_ReturnStatus IFSelect_WorkSession::ReadFile
IFSelect_ReturnStatus status = IFSelect_RetVoid; IFSelect_ReturnStatus status = IFSelect_RetVoid;
try { try {
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
Standard_Integer stat = thelibrary->ReadFile (filename,model,theprotocol); Standard_Integer stat = thelibrary->ReadFile(filename, model, theprotocol);
if (stat == 0) status = IFSelect_RetDone; if (stat == 0) status = IFSelect_RetDone;
else if (stat < 0) status = IFSelect_RetError; else if (stat < 0) status = IFSelect_RetError;
else status = IFSelect_RetFail; else status = IFSelect_RetFail;
@@ -235,6 +234,39 @@ IFSelect_ReturnStatus IFSelect_WorkSession::ReadFile
return status; return status;
} }
//=======================================================================
//function :
//purpose :
//=======================================================================
IFSelect_ReturnStatus IFSelect_WorkSession::ReadStream(const Standard_CString filename,
std::istream* istream)
{
if (thelibrary.IsNull()) return IFSelect_RetVoid;
if (theprotocol.IsNull()) return IFSelect_RetVoid;
Handle(Interface_InterfaceModel) model;
IFSelect_ReturnStatus status = IFSelect_RetVoid;
try {
OCC_CATCH_SIGNALS
Standard_Integer stat = thelibrary->ReadStream(filename, istream, model, theprotocol);
if (stat == 0) status = IFSelect_RetDone;
else if (stat < 0) status = IFSelect_RetError;
else status = IFSelect_RetFail;
}
catch (Standard_Failure const& anException) {
Handle(Message_Messenger) sout = Message::DefaultMessenger();
sout << " **** Interruption ReadFile par Exception : ****\n";
sout << anException.GetMessageString();
sout << "\n Abandon" << endl;
status = IFSelect_RetFail;
}
if (status != IFSelect_RetDone) return status;
if (model.IsNull()) return IFSelect_RetVoid;
SetModel(model);
SetLoadedFile(filename);
return status;
}
//======================================================================= //=======================================================================
//function : //function :

View File

@@ -171,6 +171,12 @@ public:
//! RetDone if OK, RetVoid if no Protocol not defined, //! RetDone if OK, RetVoid if no Protocol not defined,
//! RetError for file not found, RetFail if fail during read //! RetError for file not found, RetFail if fail during read
Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename); Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename);
//! Reads a file from stream with the WorkLibrary (sets Model and LoadedFile)
//! Returns a integer status which can be :
//! RetDone if OK, RetVoid if no Protocol not defined,
//! RetError for file not found, RetFail if fail during read
Standard_EXPORT IFSelect_ReturnStatus ReadStream (const Standard_CString filename, std::istream* istream);
//! Returns the count of Entities stored in the Model, or 0 //! Returns the count of Entities stored in the Model, or 0
Standard_EXPORT Standard_Integer NbStartingEntities() const; Standard_EXPORT Standard_Integer NbStartingEntities() const;

View File

@@ -1,12 +1,19 @@
lex.step.c lex.step.cxx
recfile.pc recfile.pc
recfile.ph recfile.ph
step.tab.c step.tab.cxx
step.tab.h step.tab.hxx
StepFile_CallFailure.cxx StepFile_CallFailure.cxx
StepFile_CallFailure.hxx StepFile_CallFailure.hxx
StepFile_Read.cxx StepFile_Read.cxx
StepFile_Read.hxx StepFile_Read.hxx
StepFile_Transfer.hxx StepFile_Transfer.hxx
stepread.c stepread.cxx
stepread.ph stepread.ph
step.lex
step.yacc
FlexLexer.h
location.hh
position.hh
stack.hh
scanner.hpp

206
src/StepFile/FlexLexer.h Normal file
View File

@@ -0,0 +1,206 @@
// -*-C++-*-
// FlexLexer.h -- define interfaces for lexical analyzer classes generated
// by flex
// Copyright (c) 1993 The Regents of the University of California.
// All rights reserved.
//
// This code is derived from software contributed to Berkeley by
// Kent Williams and Tom Epperly.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// Neither the name of the University nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE.
// This file defines FlexLexer, an abstract class which specifies the
// external interface provided to flex C++ lexer objects, and yyFlexLexer,
// which defines a particular lexer class.
//
// If you want to create multiple lexer classes, you use the -P flag
// to rename each yyFlexLexer to some other xxFlexLexer. You then
// include <FlexLexer.h> in your other sources once per lexer class:
//
// #undef yyFlexLexer
// #define yyFlexLexer xxFlexLexer
// #include <FlexLexer.h>
//
// #undef yyFlexLexer
// #define yyFlexLexer zzFlexLexer
// #include <FlexLexer.h>
// ...
#ifndef __FLEX_LEXER_H
// Never included before - need to define base class.
#define __FLEX_LEXER_H
#include <iostream>
# ifndef FLEX_STD
# define FLEX_STD std::
# endif
extern "C++" {
struct yy_buffer_state;
typedef int yy_state_type;
class FlexLexer {
public:
virtual ~FlexLexer() { }
const char* YYText() const { return yytext; }
int YYLeng() const { return yyleng; }
virtual void
yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
virtual struct yy_buffer_state*
yy_create_buffer( FLEX_STD istream* s, int size ) = 0;
virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
virtual void yyrestart( FLEX_STD istream* s ) = 0;
virtual int yylex() = 0;
// Call yylex with new input/output sources.
int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 )
{
switch_streams( new_in, new_out );
return yylex();
}
// Switch to new input/output streams. A nil stream pointer
// indicates "keep the current one".
virtual void switch_streams( FLEX_STD istream* new_in = 0,
FLEX_STD ostream* new_out = 0 ) = 0;
int lineno() const { return yylineno; }
int debug() const { return yy_flex_debug; }
void set_debug( int flag ) { yy_flex_debug = flag; }
protected:
char* yytext;
int yyleng;
int yylineno; // only maintained if you use %option yylineno
int yy_flex_debug; // only has effect with -d or "%option debug"
};
}
#endif // FLEXLEXER_H
#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
// Either this is the first time through (yyFlexLexerOnce not defined),
// or this is a repeated include to define a different flavor of
// yyFlexLexer, as discussed in the flex manual.
#define yyFlexLexerOnce
extern "C++" {
class yyFlexLexer : public FlexLexer {
public:
// arg_yyin and arg_yyout default to the cin and cout, but we
// only make that assignment when initializing in yylex().
yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 );
virtual ~yyFlexLexer();
void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size );
void yy_delete_buffer( struct yy_buffer_state* b );
void yyrestart( FLEX_STD istream* s );
void yypush_buffer_state( struct yy_buffer_state* new_buffer );
void yypop_buffer_state();
virtual int yylex();
virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 );
virtual int yywrap();
protected:
virtual int LexerInput( char* buf, int max_size );
virtual void LexerOutput( const char* buf, int size );
virtual void LexerError( const char* msg );
void yyunput( int c, char* buf_ptr );
int yyinput();
void yy_load_buffer_state();
void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s );
void yy_flush_buffer( struct yy_buffer_state* b );
int yy_start_stack_ptr;
int yy_start_stack_depth;
int* yy_start_stack;
void yy_push_state( int new_state );
void yy_pop_state();
int yy_top_state();
yy_state_type yy_get_previous_state();
yy_state_type yy_try_NUL_trans( yy_state_type current_state );
int yy_get_next_buffer();
FLEX_STD istream* yyin; // input source for default LexerInput
FLEX_STD ostream* yyout; // output sink for default LexerOutput
// yy_hold_char holds the character lost when yytext is formed.
char yy_hold_char;
// Number of characters read into yy_ch_buf.
int yy_n_chars;
// Points to current character in buffer.
char* yy_c_buf_p;
int yy_init; // whether we need to initialize
int yy_start; // start state number
// Flag which is used to allow yywrap()'s to do buffer switches
// instead of setting up a fresh yyin. A bit of a hack ...
int yy_did_buffer_switch_on_eof;
size_t yy_buffer_stack_top; /**< index of top of stack. */
size_t yy_buffer_stack_max; /**< capacity of stack. */
struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
void yyensure_buffer_stack(void);
// The following are not always needed, but may be depending
// on use of certain flex features (like REJECT or yymore()).
yy_state_type yy_last_accepting_state;
char* yy_last_accepting_cpos;
yy_state_type* yy_state_buf;
yy_state_type* yy_state_ptr;
char* yy_full_match;
int* yy_full_state;
int yy_full_lp;
int yy_lp;
int yy_looking_for_trail_begin;
int yy_more_flag;
int yy_more_len;
int yy_more_offset;
int yy_prev_more_offset;
};
}
#endif // yyFlexLexer || ! yyFlexLexerOnce

View File

@@ -16,7 +16,7 @@
#include <Standard_Failure.hxx> #include <Standard_Failure.hxx>
#include <StepFile_CallFailure.hxx> #include <StepFile_CallFailure.hxx>
void StepFile_CallFailure(char * const message) void StepFile_CallFailure(const char * message)
{ {
throw Standard_Failure(message); throw Standard_Failure(message);
} }

View File

@@ -14,4 +14,4 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
#endif #endif
void StepFile_CallFailure(char * const message); void StepFile_CallFailure(const char * message);

View File

@@ -25,13 +25,19 @@
// Compilation conditionnelle : concerne les mesures de performances // Compilation conditionnelle : concerne les mesures de performances
#include <stdio.h> #include <stdio.h>
#include <iostream>
#include "recfile.ph" #include "recfile.ph"
#include "stepread.ph" #include "stepread.ph"
extern "C" void recfile_modeprint (int mode); // controle trace recfile
// recfile_modeprint est declare a part
#ifdef __cplusplus
extern "C" {
#endif
void recfile_modeprint (int mode); // controle trace recfile
// recfile_modeprint est declare a part
#ifdef __cplusplus
}
#endif
#include <Interface_ParamType.hxx> #include <Interface_ParamType.hxx>
#include <Interface_Protocol.hxx> #include <Interface_Protocol.hxx>
#include <Interface_Check.hxx> #include <Interface_Check.hxx>
@@ -65,9 +71,9 @@ void StepFile_ReadTrace (const Standard_Integer mode)
modepr = mode; // recfile_modeprint est rappele a chaque lecture de fichier modepr = mode; // recfile_modeprint est rappele a chaque lecture de fichier
} }
static Standard_Integer StepFile_Read static Standard_Integer StepFile_Read
(char* nomfic, (char* nomfic,
std::istream* istream,
const Handle(StepData_StepModel)& stepmodel, const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol, const Handle(StepData_Protocol)& protocol,
const Handle(StepData_FileRecognizer)& recoheader, const Handle(StepData_FileRecognizer)& recoheader,
@@ -81,7 +87,7 @@ Standard_Integer StepFile_Read
const Handle(StepData_FileRecognizer)& recodata) const Handle(StepData_FileRecognizer)& recodata)
{ {
return StepFile_Read return StepFile_Read
(nomfic,stepmodel, (nomfic,0,stepmodel,
Handle(StepData_Protocol)::DownCast(Interface_Protocol::Active()), Handle(StepData_Protocol)::DownCast(Interface_Protocol::Active()),
recoheader,recodata); recoheader,recodata);
} }
@@ -93,7 +99,7 @@ Standard_Integer StepFile_Read
const Handle(StepData_Protocol)& protocol) const Handle(StepData_Protocol)& protocol)
{ {
Handle(StepData_FileRecognizer) nulreco; Handle(StepData_FileRecognizer) nulreco;
return StepFile_Read (nomfic,stepmodel,protocol,recoheader,nulreco); return StepFile_Read (nomfic,0,stepmodel,protocol,recoheader,nulreco);
} }
Standard_Integer StepFile_Read Standard_Integer StepFile_Read
@@ -102,7 +108,17 @@ Standard_Integer StepFile_Read
const Handle(StepData_Protocol)& protocol) const Handle(StepData_Protocol)& protocol)
{ {
Handle(StepData_FileRecognizer) nulreco; Handle(StepData_FileRecognizer) nulreco;
return StepFile_Read (nomfic,stepmodel,protocol,nulreco,nulreco); return StepFile_Read (nomfic,0,stepmodel,protocol,nulreco,nulreco);
}
Standard_Integer StepFile_Read
(char* nomfic,
std::istream* istream,
const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol)
{
Handle(StepData_FileRecognizer) nulreco;
return StepFile_Read (nomfic,istream,stepmodel,protocol,nulreco,nulreco);
} }
// ## ## ## ## ## ## Corps de la Routine ## ## ## ## ## ## // ## ## ## ## ## ## Corps de la Routine ## ## ## ## ## ##
@@ -111,6 +127,7 @@ static Interface_ParamType LesTypes[10]; // passage types (recstep/Interface)
Standard_Integer StepFile_Read Standard_Integer StepFile_Read
(char* nomfic, (char* nomfic,
std::istream* istream,
const Handle(StepData_StepModel)& stepmodel, const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol, const Handle(StepData_Protocol)& protocol,
const Handle(StepData_FileRecognizer)& recoheader, const Handle(StepData_FileRecognizer)& recoheader,
@@ -122,8 +139,12 @@ Standard_Integer StepFile_Read
checkread->Clear(); checkread->Clear();
recfile_modeprint ( (modepr > 0 ? modepr-1 : 0) ); recfile_modeprint ( (modepr > 0 ? modepr-1 : 0) );
FILE* newin = stepread_setinput(ficnom); std::ifstream newifstream;
if (!newin) return -1; if (!istream) {
stepread_setinput(newifstream, ficnom);
istream = &newifstream;
}
if (!istream) return -1;
#ifdef CHRONOMESURE #ifdef CHRONOMESURE
Standard_Integer n ; Standard_Integer n ;
OSD_Timer c ; OSD_Timer c ;
@@ -134,7 +155,11 @@ Standard_Integer StepFile_Read
try { try {
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
if (stepread () != 0) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; } if (stepread(istream) != 0) {
lir_file_fin(3);
stepread_endinput(newifstream, ficnom);
return 1;
}
} }
catch (Standard_Failure const& anException) { catch (Standard_Failure const& anException) {
#ifdef OCCT_DEBUG #ifdef OCCT_DEBUG
@@ -144,17 +169,17 @@ Standard_Integer StepFile_Read
#endif #endif
(void)anException; (void)anException;
lir_file_fin(3); lir_file_fin(3);
stepread_endinput (newin,ficnom); stepread_endinput(newifstream, ficnom);
return 1; return 1;
} }
// Continue reading of file despite of possible fails
//if (checkread->HasFailed()) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; } // Continue reading of file despite of possible fails
// if (checkread->HasFailed()) { lir_file_fin(3); stepread_endinput(newifstream, ficnom); return 1; }
#ifdef CHRONOMESURE #ifdef CHRONOMESURE
sout << " ... STEP File Read ... " << endl; sout << " ... STEP File Read ... " << endl;
c.Show(); c.Show();
#endif #endif
// Creation du StepReaderData // Creation du StepReaderData
LesTypes[rec_argNondef] = Interface_ParamVoid ; LesTypes[rec_argNondef] = Interface_ParamVoid ;
@@ -224,8 +249,8 @@ Standard_Integer StepFile_Read
n = stepmodel->NbEntities() ; n = stepmodel->NbEntities() ;
sout << " STEP Loading done : " << n << " Entities" << endl; sout << " STEP Loading done : " << n << " Entities" << endl;
#endif #endif
stepread_endinput(newifstream, ficnom);
stepread_endinput (newin,ficnom); return 0 ; return 0;
} }
void StepFile_Interrupt (char* mess) void StepFile_Interrupt (char* mess)

View File

@@ -27,6 +27,7 @@
#ifndef StepFile_Read_HeaderFile #ifndef StepFile_Read_HeaderFile
#define StepFile_Read_HeaderFile #define StepFile_Read_HeaderFile
#include <iostream>
//# include <stepread.h> : sauf recfile_modeprint, declare ici //# include <stepread.h> : sauf recfile_modeprint, declare ici
# include <StepData_StepModel.hxx> # include <StepData_StepModel.hxx>
# include <StepData_FileRecognizer.hxx> # include <StepData_FileRecognizer.hxx>
@@ -52,5 +53,11 @@ Standard_EXPORT Standard_Integer StepFile_Read
(char* nomfic, (char* nomfic,
const Handle(StepData_StepModel)& stepmodel, const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol); // Header & Data const Handle(StepData_Protocol)& protocol); // Header & Data
Standard_EXPORT Standard_Integer StepFile_Read
(char* nomfic,
std::istream* istream,
const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol); // Header & Data
#endif #endif

File diff suppressed because it is too large Load Diff

1920
src/StepFile/lex.step.cxx Normal file

File diff suppressed because it is too large Load Diff

181
src/StepFile/location.hh Normal file
View File

@@ -0,0 +1,181 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Locations for Bison parsers in C++
Copyright (C) 2002-2007, 2009-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/**
** \file location.hh
** Define the yy::location class.
*/
#ifndef YY_YY_LOCATION_HH_INCLUDED
# define YY_YY_LOCATION_HH_INCLUDED
# include "position.hh"
namespace yy {
/* Line 166 of location.cc */
#line 47 "location.hh"
/// Abstract a location.
class location
{
public:
/// Construct a location from \a b to \a e.
location (const position& b, const position& e)
: begin (b)
, end (e)
{
}
/// Construct a 0-width location in \a p.
explicit location (const position& p = position ())
: begin (p)
, end (p)
{
}
/// Construct a 0-width location in \a f, \a l, \a c.
explicit location (std::string* f,
unsigned int l = 1u,
unsigned int c = 1u)
: begin (f, l, c)
, end (f, l, c)
{
}
/// Initialization.
void initialize (std::string* f = YY_NULL,
unsigned int l = 1u,
unsigned int c = 1u)
{
begin.initialize (f, l, c);
end = begin;
}
/** \name Line and Column related manipulators
** \{ */
public:
/// Reset initial location to final location.
void step ()
{
begin = end;
}
/// Extend the current location to the COUNT next columns.
void columns (unsigned int count = 1)
{
end += count;
}
/// Extend the current location to the COUNT next lines.
void lines (unsigned int count = 1)
{
end.lines (count);
}
/** \} */
public:
/// Beginning of the located region.
position begin;
/// End of the located region.
position end;
};
/// Join two location objects to create a location.
inline const location operator+ (const location& begin, const location& end)
{
location res = begin;
res.end = end.end;
return res;
}
/// Add two location objects.
inline const location operator+ (const location& begin, unsigned int width)
{
location res = begin;
res.columns (width);
return res;
}
/// Add and assign a location.
inline location& operator+= (location& res, unsigned int width)
{
res.columns (width);
return res;
}
/// Compare two location objects.
inline bool
operator== (const location& loc1, const location& loc2)
{
return loc1.begin == loc2.begin && loc1.end == loc2.end;
}
/// Compare two location objects.
inline bool
operator!= (const location& loc1, const location& loc2)
{
return !(loc1 == loc2);
}
/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param loc a reference to the location to redirect
**
** Avoid duplicate information.
*/
template <typename YYChar>
inline std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
{
position last = loc.end - 1;
ostr << loc.begin;
if (last.filename
&& (!loc.begin.filename
|| *loc.begin.filename != *last.filename))
ostr << '-' << last;
else if (loc.begin.line != last.line)
ostr << '-' << last.line << '.' << last.column;
else if (loc.begin.column != last.column)
ostr << '-' << last.column;
return ostr;
}
} // yy
/* Line 296 of location.cc */
#line 180 "location.hh"
#endif /* !YY_YY_LOCATION_HH_INCLUDED */

172
src/StepFile/position.hh Normal file
View File

@@ -0,0 +1,172 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Positions for Bison parsers in C++
Copyright (C) 2002-2007, 2009-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/**
** \file position.hh
** Define the yy::position class.
*/
#ifndef YY_YY_POSITION_HH_INCLUDED
# define YY_YY_POSITION_HH_INCLUDED
# include <algorithm> // std::max
# include <iostream>
# include <string>
# ifndef YY_NULL
# if defined __cplusplus && 201103L <= __cplusplus
# define YY_NULL nullptr
# else
# define YY_NULL 0
# endif
# endif
namespace yy {
/* Line 36 of location.cc */
#line 57 "position.hh"
/// Abstract a position.
class position
{
public:
/// Construct a position.
explicit position (std::string* f = YY_NULL,
unsigned int l = 1u,
unsigned int c = 1u)
: filename (f)
, line (l)
, column (c)
{
}
/// Initialization.
void initialize (std::string* fn = YY_NULL,
unsigned int l = 1u,
unsigned int c = 1u)
{
filename = fn;
line = l;
column = c;
}
/** \name Line and Column related manipulators
** \{ */
/// (line related) Advance to the COUNT next lines.
void lines (int count = 1)
{
column = 1u;
line += count;
}
/// (column related) Advance to the COUNT next columns.
void columns (int count = 1)
{
column = std::max (1u, column + count);
}
/** \} */
/// File name to which this position refers.
std::string* filename;
/// Current line number.
unsigned int line;
/// Current column number.
unsigned int column;
};
/// Add and assign a position.
inline position&
operator+= (position& res, const int width)
{
res.columns (width);
return res;
}
/// Add two position objects.
inline const position
operator+ (const position& begin, const int width)
{
position res = begin;
return res += width;
}
/// Add and assign a position.
inline position&
operator-= (position& res, const int width)
{
return res += -width;
}
/// Add two position objects.
inline const position
operator- (const position& begin, const int width)
{
return begin + -width;
}
/// Compare two position objects.
inline bool
operator== (const position& pos1, const position& pos2)
{
return (pos1.line == pos2.line
&& pos1.column == pos2.column
&& (pos1.filename == pos2.filename
|| (pos1.filename && pos2.filename
&& *pos1.filename == *pos2.filename)));
}
/// Compare two position objects.
inline bool
operator!= (const position& pos1, const position& pos2)
{
return !(pos1 == pos2);
}
/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param pos a reference to the position to redirect
*/
template <typename YYChar>
inline std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
{
if (pos.filename)
ostr << *pos.filename << ':';
return ostr << pos.line << '.' << pos.column;
}
} // yy
/* Line 148 of location.cc */
#line 172 "position.hh"
#endif /* !YY_YY_POSITION_HH_INCLUDED */

View File

@@ -52,9 +52,10 @@
static char txt_cart_p[] = "CARTESIAN_POINT"; static char txt_cart_p[] = "CARTESIAN_POINT";
void rec_restext(char* newtext, int lentext) /* destine a etre appele de l'exterieur */ void rec_restext(const char* constnewtext, int lentext) /* destine a etre appele de l'exterieur */
{ {
char *res, *text; char *res, *text, *newtext;
newtext = const_cast<char*>(constnewtext);
if(strcmp(newtext,txt_cart_p)==0) { if(strcmp(newtext,txt_cart_p)==0) {
restext = txt_cart_p; restext = txt_cart_p;
return; return;
@@ -167,9 +168,18 @@ static char idzero[] = "#0";
/* Trace pour controle */ /* Trace pour controle */
#ifdef __cplusplus
extern "C" {
#endif
void recfile_modeprint(int mode) void recfile_modeprint(int mode)
{ modeprint = mode; } { modeprint = mode; }
#ifdef __cplusplus
}
#endif
static int lastno; static int lastno;
extern int steplineno; extern int steplineno;
extern int modcom; extern int modcom;
@@ -482,7 +492,9 @@ void scope_fin()
La liberation de la memoire est faite par lir_file_fin, en une fois La liberation de la memoire est faite par lir_file_fin, en une fois
*/ */
#ifdef __cplusplus
extern "C" {
#endif
void lir_file_nbr(int* nbh, int* nbr, int* nbp) void lir_file_nbr(int* nbh, int* nbr, int* nbp)
/* initialise le traitement et retourne la taille du directory et du header */ /* initialise le traitement et retourne la taille du directory et du header */
{ {
@@ -562,6 +574,9 @@ int lir_file_arg(int* type, char* *val)
return (1) ; return (1) ;
} }
#ifdef __cplusplus
}
#endif
/* Verification de l'integrite des donnees */ /* Verification de l'integrite des donnees */
@@ -599,6 +614,3 @@ void rec_check(int mode)
("Liste des records pourrie, nb note %d relu %d\n",nbrec,nr) ; ("Liste des records pourrie, nb note %d relu %d\n",nbrec,nr) ;
} }
void steperror (char *mess);
int steplex (void);

36
src/StepFile/scanner.hpp Normal file
View File

@@ -0,0 +1,36 @@
#ifndef __SCANNER_HPP__INCLUDED__
#define __SCANNER_HPP__INCLUDED__
#undef yyFlexLexer
#include <FlexLexer.h>
#include "step.tab.hxx"
// Tell flex which function to define
#ifdef YY_DECL
# undef YY_DECL
#endif
#define YY_DECL \
int yy::scanner::lex( \
yy::parser::semantic_type* /*yylval*/, \
yy::parser::location_type* /*yylloc*/)
namespace yy
{
// To feed data back to bison, the yylex method needs yylval and
// yylloc parameters. Since the yyFlexLexer class is defined in the
// system header <FlexLexer.h> the signature of its yylex() method
// can not be changed anymore. This makes it necessary to derive a
// scanner class that provides a method with the desired signature:
class scanner : public yyFlexLexer
{
public:
explicit scanner(std::istream* in = 0, std::ostream* out = 0);
int lex(yy::parser::semantic_type* /*yylval*/,
yy::parser::location_type* /*yylloc*/);
};
}
#endif // include guard

137
src/StepFile/stack.hh Normal file
View File

@@ -0,0 +1,137 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Stack handling for Bison parsers in C++
Copyright (C) 2002-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/**
** \file stack.hh
** Define the yy::stack class.
*/
#ifndef YY_YY_STACK_HH_INCLUDED
# define YY_YY_STACK_HH_INCLUDED
# include <deque>
// disable MSVC warnings in bison code
#ifdef _MSC_VER
#pragma warning(disable:4512)
#endif
namespace yy {
/* Line 34 of stack.hh */
#line 47 "stack.hh"
template <class T, class S = std::deque<T> >
class stack
{
public:
// Hide our reversed order.
typedef typename S::reverse_iterator iterator;
typedef typename S::const_reverse_iterator const_iterator;
stack () : seq_ ()
{
}
stack (unsigned int n) : seq_ (n)
{
}
inline
T&
operator [] (unsigned int i)
{
return seq_[i];
}
inline
const T&
operator [] (unsigned int i) const
{
return seq_[i];
}
inline
void
push (const T& t)
{
seq_.push_front (t);
}
inline
void
pop (unsigned int n = 1)
{
for (; n; --n)
seq_.pop_front ();
}
inline
size_t
height () const
{
return seq_.size ();
}
inline const_iterator begin () const { return seq_.rbegin (); }
inline const_iterator end () const { return seq_.rend (); }
private:
S seq_;
};
/// Present a slice of the top of a stack.
template <class T, class S = stack<T> >
class slice
{
public:
slice (const S& stack, unsigned int range)
: stack_ (stack)
, range_ (range)
{
}
inline
const T&
operator [] (unsigned int i) const
{
return stack_[range_ - i];
}
private:
const S& stack_;
unsigned int range_;
};
} // yy
/* Line 116 of stack.hh */
#line 132 "stack.hh"
#endif /* !YY_YY_STACK_HH_INCLUDED */

View File

@@ -13,12 +13,27 @@
commercial license or contractual agreement. commercial license or contractual agreement.
*/ */
%option outfile="lex.step.cxx"
/*
c++ generate C++ parser class
8bit don't fail on 8-bit input characters
warn warn about inconsistencies
nodefault don't create default echo-all rule
noyywrap don't use yywrap() function
yylineno maintains the number of the current line
*/
%option c++
%option 8bit warn nodefault
%option noyywrap
%option yylineno
%{ %{
#include "step.tab.h" #include "step.tab.hxx"
#include "scanner.hpp"
#include "recfile.ph" #include "recfile.ph"
#include "stdio.h" #include "stdio.h"
#include <StepFile_CallFailure.hxx> #include <StepFile_CallFailure.hxx>
typedef yy::parser::token token;
/* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect /* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect
long string in files Henri.stp and 401.stp*/ long string in files Henri.stp and 401.stp*/
#define YY_FATAL_ERROR(msg) StepFile_CallFailure( msg ) #define YY_FATAL_ERROR(msg) StepFile_CallFailure( msg )
@@ -30,15 +45,14 @@ long string in files Henri.stp and 401.stp*/
void steperror ( FILE *input_file ); void steperror ( FILE *input_file );
void steprestart ( FILE *input_file ); void steprestart ( FILE *input_file );
*/ */
void rec_restext(char *newtext, int lentext);
void rec_restext(const char *constnewtext, int lentext);
void rec_typarg(int argtype); void rec_typarg(int argtype);
int steplineno; /* Comptage de ligne (ben oui, fait tout faire) */ int steplineno; /* Comptage de ligne (ben oui, fait tout faire) */
int modcom = 0; /* Commentaires type C */ int modcom = 0; /* Commentaires type C */
int modend = 0; /* Flag for finishing of the STEP file */ int modend = 0; /* Flag for finishing of the STEP file */
void resultat () /* Resultat alloue dynamiquement, "jete" une fois lu */
{ if (modcom == 0) rec_restext(yytext,yyleng); }
// MSVC specifics // MSVC specifics
#ifdef _MSC_VER #ifdef _MSC_VER
@@ -48,7 +62,7 @@ void rec_typarg(int argtype);
#if defined(__INTEL_COMPILER) #if defined(__INTEL_COMPILER)
#pragma warning(disable:177 1786 1736) #pragma warning(disable:177 1786 1736)
#else #else
#pragma warning(disable:4131 4244 4273 4267 4127) #pragma warning(disable:4131 4244 4273 4267 4127 4100)
#endif #endif
// Avoid includion of unistd.h if parser is generated on Linux (flex 2.5.35) // Avoid includion of unistd.h if parser is generated on Linux (flex 2.5.35)
@@ -62,43 +76,56 @@ void rec_typarg(int argtype);
#endif #endif
%} %}
%% %%
" " {;} " " {;}
" " {;} " " {;}
[\n] { steplineno ++; } [\n] { steplineno ++; }
[\r] {;} /* abv 30.06.00: for reading DOS files */ [\r] {;} /* abv 30.06.00: for reading DOS files */
[\0]+ {;} /* fix from C21. for test load e3i file with line 15 with null symbols */ [\0]+ {;} /* fix from C21. for test load e3i file with line 15 with null symbols */
#[0-9]+/= { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::ENTITY); } }
#[0-9]+/= { resultat(); if (modcom == 0) return(ENTITY); } #[0-9]+/[ ]*= { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::ENTITY); } }
#[0-9]+/[ ]*= { resultat(); if (modcom == 0) return(ENTITY); } #[0-9]+ { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::IDENT); } }
#[0-9]+ { resultat(); if (modcom == 0) return(IDENT); } [-+0-9][0-9]* { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argInteger); return(token::QUID); } }
[-+0-9][0-9]* { resultat(); if (modcom == 0) { rec_typarg(rec_argInteger); return(QUID); } } [-+\.0-9][\.0-9]+ { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argFloat); return(token::QUID); } }
[-+\.0-9][\.0-9]+ { resultat(); if (modcom == 0) { rec_typarg(rec_argFloat); return(QUID); } } [-+\.0-9][\.0-9]+E[-+0-9][0-9]* { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argFloat); return(token::QUID); } }
[-+\.0-9][\.0-9]+E[-+0-9][0-9]* { resultat(); if (modcom == 0) { rec_typarg(rec_argFloat); return(QUID); } } [\']([\n]|[\000\011-\046\050-\176\201-\237\240-\777]|[\047][\047])*[\'] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argText); return(token::QUID); } }
[\']([\n]|[\000\011-\046\050-\176\201-\237\240-\777]|[\047][\047])*[\'] { resultat(); if (modcom == 0) { rec_typarg(rec_argText); return(QUID); } } ["][0-9A-F]+["] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argHexa); return(token::QUID); } }
["][0-9A-F]+["] { resultat(); if (modcom == 0) { rec_typarg(rec_argHexa); return(QUID); } } [.][A-Z0-9_]+[.] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argEnum); return(token::QUID); } }
[.][A-Z0-9_]+[.] { resultat(); if (modcom == 0) { rec_typarg(rec_argEnum); return(QUID); } }
[(] { if (modcom == 0) return ('('); } [(] { if (modcom == 0) return ('('); }
[)] { if (modcom == 0) return (')'); } [)] { if (modcom == 0) return (')'); }
[,] { if (modcom == 0) return (','); } [,] { if (modcom == 0) return (','); }
[$] { resultat(); if (modcom == 0) { rec_typarg(rec_argNondef); return(QUID); } } [$] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argNondef); return(token::QUID); } }
[=] { if (modcom == 0) return ('='); } [=] { if (modcom == 0) return ('='); }
[;] { if (modcom == 0) return (';'); } [;] { if (modcom == 0) return (';'); }
"/*" { modcom = 1; } "/*" { modcom = 1; }
"*/" { if (modend == 0) modcom = 0; } "*/" { if (modend == 0) modcom = 0; }
STEP; { if (modcom == 0) return(STEP); } STEP; { if (modcom == 0) return(token::STEP); }
HEADER; { if (modcom == 0) return(HEADER); } HEADER; { if (modcom == 0) return(token::HEADER); }
ENDSEC; { if (modcom == 0) return(ENDSEC); } ENDSEC; { if (modcom == 0) return(token::ENDSEC); }
DATA; { if (modcom == 0) return(DATA); } DATA; { if (modcom == 0) return(token::DATA); }
ENDSTEP; { if (modend == 0) {modcom = 0; return(ENDSTEP);} } ENDSTEP; { if (modend == 0) {modcom = 0; return(token::ENDSTEP);} }
"ENDSTEP;".* { if (modend == 0) {modcom = 0; return(ENDSTEP);} } "ENDSTEP;".* { if (modend == 0) {modcom = 0; return(token::ENDSTEP);} }
END-ISO[0-9\-]*; { modcom = 1; modend = 1; return(ENDSTEP); } END-ISO[0-9\-]*; { modcom = 1; modend = 1; return(token::ENDSTEP); }
ISO[0-9\-]*; { if (modend == 0) {modcom = 0; return(STEP); } } ISO[0-9\-]*; { if (modend == 0) {modcom = 0; return(token::STEP); } }
[/] { if (modcom == 0) return ('/'); } [/] { if (modcom == 0) return ('/'); }
&SCOPE { if (modcom == 0) return(SCOPE); } &SCOPE { if (modcom == 0) return(token::SCOPE); }
ENDSCOPE { if (modcom == 0) return(ENDSCOPE); } ENDSCOPE { if (modcom == 0) return(token::ENDSCOPE); }
[a-zA-Z0-9_]+ { resultat(); if (modcom == 0) return(TYPE); } [a-zA-Z0-9_]+ { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::TYPE); } }
![a-zA-Z0-9_]+ { resultat(); if (modcom == 0) return(TYPE); } ![a-zA-Z0-9_]+ { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::TYPE); } }
[^)] { resultat(); if (modcom == 0) { rec_typarg(rec_argMisc); return(QUID); } } [^)] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argMisc); return(token::QUID); } }
%%
yy::scanner::scanner(std::istream* in, std::ostream* out)
: yyFlexLexer(in, out)
{
}
int yyFlexLexer::yylex()
{
throw std::logic_error(
"The yylex() exists for technical reasons and must not be used.");
}

File diff suppressed because it is too large Load Diff

1076
src/StepFile/step.tab.cxx Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,93 +0,0 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_STEP_STEP_TAB_H_INCLUDED
# define YY_STEP_STEP_TAB_H_INCLUDED
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int stepdebug;
#endif
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
STEP = 258,
HEADER = 259,
ENDSEC = 260,
DATA = 261,
ENDSTEP = 262,
SCOPE = 263,
ENDSCOPE = 264,
ENTITY = 265,
TYPE = 266,
INTEGER = 267,
FLOAT = 268,
IDENT = 269,
TEXT = 270,
NONDEF = 271,
ENUM = 272,
HEXA = 273,
QUID = 274
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE steplval;
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int stepparse (void *YYPARSE_PARAM);
#else
int stepparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int stepparse (void);
#else
int stepparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_STEP_STEP_TAB_H_INCLUDED */

285
src/StepFile/step.tab.hxx Normal file
View File

@@ -0,0 +1,285 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Skeleton interface for Bison LALR(1) parsers in C++
Copyright (C) 2002-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/**
** \file step.tab.hxx
** Define the yy::parser class.
*/
/* C++ LALR(1) parser skeleton written by Akim Demaille. */
#ifndef YY_YY_STEP_TAB_HXX_INCLUDED
# define YY_YY_STEP_TAB_HXX_INCLUDED
/* "%code requires" blocks. */
/* Line 33 of lalr1.cc */
#line 31 "StepFile/step.yacc"
#include "location.hh"
#include <stdexcept>
namespace yy {
class scanner;
};
/* Line 33 of lalr1.cc */
#line 56 "step.tab.hxx"
#include <string>
#include <iostream>
#include "stack.hh"
#include "location.hh"
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
namespace yy {
/* Line 33 of lalr1.cc */
#line 72 "step.tab.hxx"
/// A Bison parser.
class parser
{
public:
/// Symbol semantic values.
#ifndef YYSTYPE
typedef int semantic_type;
#else
typedef YYSTYPE semantic_type;
#endif
/// Symbol locations.
typedef location location_type;
/// Tokens.
struct token
{
/* Tokens. */
enum yytokentype {
STEP = 258,
HEADER = 259,
ENDSEC = 260,
DATA = 261,
ENDSTEP = 262,
SCOPE = 263,
ENDSCOPE = 264,
ENTITY = 265,
TYPE = 266,
INTEGER = 267,
FLOAT = 268,
IDENT = 269,
TEXT = 270,
NONDEF = 271,
ENUM = 272,
HEXA = 273,
QUID = 274
};
};
/// Token type.
typedef token::yytokentype token_type;
/// Build a parser object.
parser (yy::scanner* scanner_yyarg);
virtual ~parser ();
/// Parse.
/// \returns 0 iff parsing succeeded.
virtual int parse ();
#if YYDEBUG
/// The current debugging stream.
std::ostream& debug_stream () const;
/// Set the current debugging stream.
void set_debug_stream (std::ostream &);
/// Type for debugging levels.
typedef int debug_level_type;
/// The current debugging level.
debug_level_type debug_level () const;
/// Set the current debugging level.
void set_debug_level (debug_level_type l);
#endif
private:
/// Report a syntax error.
/// \param loc where the syntax error is found.
/// \param msg a description of the syntax error.
virtual void error (const std::string& msg);
/// Generate an error message.
/// \param state the state where the error occurred.
/// \param tok the lookahead token.
virtual std::string yysyntax_error_ (int yystate, int tok);
#if YYDEBUG
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
virtual void yy_symbol_value_print_ (int yytype,
const semantic_type* yyvaluep,
const location_type* yylocationp);
/// \brief Report a symbol on the debug stream.
/// \param yytype The token type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
virtual void yy_symbol_print_ (int yytype,
const semantic_type* yyvaluep,
const location_type* yylocationp);
#endif
/// State numbers.
typedef int state_type;
/// State stack type.
typedef stack<state_type> state_stack_type;
/// Semantic value stack type.
typedef stack<semantic_type> semantic_stack_type;
/// location stack type.
typedef stack<location_type> location_stack_type;
/// The state stack.
state_stack_type yystate_stack_;
/// The semantic value stack.
semantic_stack_type yysemantic_stack_;
/// The location stack.
location_stack_type yylocation_stack_;
/// Whether the given \c yypact_ value indicates a defaulted state.
/// \param yyvalue the value to check
static bool yy_pact_value_is_default_ (int yyvalue);
/// Whether the given \c yytable_ value indicates a syntax error.
/// \param yyvalue the value to check
static bool yy_table_value_is_error_ (int yyvalue);
/// Internal symbol numbers.
typedef unsigned char token_number_type;
/* Tables. */
/// For a state, the index in \a yytable_ of its portion.
static const signed char yypact_[];
static const signed char yypact_ninf_;
/// For a state, default reduction number.
/// Unless\a yytable_ specifies something else to do.
/// Zero means the default is an error.
static const unsigned char yydefact_[];
static const signed char yypgoto_[];
static const signed char yydefgoto_[];
/// What to do in a state.
/// \a yytable_[yypact_[s]]: what to do in state \a s.
/// - if positive, shift that token.
/// - if negative, reduce the rule which number is the opposite.
/// - if zero, do what YYDEFACT says.
static const signed char yytable_[];
static const signed char yytable_ninf_;
static const unsigned char yycheck_[];
/// For a state, its accessing symbol.
static const unsigned char yystos_[];
/// For a rule, its LHS.
static const unsigned char yyr1_[];
/// For a rule, its RHS length.
static const unsigned char yyr2_[];
#if YYDEBUG
/// For a symbol, its name in clear.
static const char* const yytname_[];
/// A type to store symbol numbers and -1.
typedef signed char rhs_number_type;
/// A `-1'-separated list of the rules' RHS.
static const rhs_number_type yyrhs_[];
/// For each rule, the index of the first RHS symbol in \a yyrhs_.
static const unsigned char yyprhs_[];
/// For each rule, its source line number.
static const unsigned char yyrline_[];
/// For each scanner token number, its symbol number.
static const unsigned short int yytoken_number_[];
/// Report on the debug stream that the rule \a r is going to be reduced.
virtual void yy_reduce_print_ (int r);
/// Print the state stack on the debug stream.
virtual void yystack_print_ ();
/* Debugging. */
int yydebug_;
std::ostream* yycdebug_;
#endif
/// Convert a scanner token number \a t to a symbol number.
token_number_type yytranslate_ (int t);
/// \brief Reclaim the memory associated to a symbol.
/// \param yymsg Why this token is reclaimed.
/// If null, do not display the symbol, just free it.
/// \param yytype The symbol type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
inline void yydestruct_ (const char* yymsg,
int yytype,
semantic_type* yyvaluep,
location_type* yylocationp);
/// Pop \a n symbols the three stacks.
inline void yypop_ (unsigned int n = 1);
/* Constants. */
static const int yyeof_;
/* LAST_ -- Last index in TABLE_. */
static const int yylast_;
static const int yynnts_;
static const int yyempty_;
static const int yyfinal_;
static const int yyterror_;
static const int yyerrcode_;
static const int yyntokens_;
static const unsigned int yyuser_token_number_max_;
static const token_number_type yyundef_token_;
/* User arguments. */
yy::scanner* scanner;
};
} // yy
/* Line 33 of lalr1.cc */
#line 282 "step.tab.hxx"
#endif /* !YY_YY_STEP_TAB_HXX_INCLUDED */

View File

@@ -13,11 +13,35 @@
commercial license or contractual agreement. commercial license or contractual agreement.
*/ */
%output "step.tab.cxx"
%defines "step.tab.hxx"
%language "C++"
%require "2.7"
/* C++ parser interface */
%skeleton "lalr1.cc"
%parse-param {yy::scanner* scanner}
%locations
%token STEP HEADER ENDSEC DATA ENDSTEP SCOPE ENDSCOPE ENTITY TYPE INTEGER FLOAT IDENT TEXT NONDEF ENUM HEXA QUID %token STEP HEADER ENDSEC DATA ENDSTEP SCOPE ENDSCOPE ENTITY TYPE INTEGER FLOAT IDENT TEXT NONDEF ENUM HEXA QUID
%start stepf %start stepf
%{
%code requires {
#include "location.hh"
#include <stdexcept>
namespace yy {
class scanner;
};
}
%code {
#include "recfile.ph" /* definitions des types d'arguments */ #include "recfile.ph" /* definitions des types d'arguments */
#include "recfile.pc" /* la-dedans, tout y est */ #include "recfile.pc" /* la-dedans, tout y est */
#include "scanner.hpp"
#undef yylex
#define yylex scanner->lex
/* /*
#define stepparse STEPparse #define stepparse STEPparse
#define steplex STEPlex #define steplex STEPlex
@@ -31,6 +55,7 @@
#define stepnerrs STEPnerrs #define stepnerrs STEPnerrs
#define steperror STEPerror #define steperror STEPerror
*/ */
#define stepclearin yychar = -1 #define stepclearin yychar = -1
#define steperrok yyerrflag = 0 #define steperrok yyerrflag = 0
@@ -52,12 +77,12 @@
// disable MSVC warnings in bison code // disable MSVC warnings in bison code
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable:4244 4131 4127 4702) #pragma warning(disable:4065 4244 4131 4127 4702)
#define YYMALLOC malloc #define YYMALLOC malloc
#define YYFREE free #define YYFREE free
#endif #endif
void StepFile_Interrupt (char* nomfic); /* rln 13.09.00 port on HP*/
%} }
%% %%
/* N.B. : les commentaires sont filtres par LEX */ /* N.B. : les commentaires sont filtres par LEX */
/* La fin vide (selon systeme emetteur) est filtree ici */ /* La fin vide (selon systeme emetteur) est filtree ici */
@@ -85,7 +110,7 @@ unarg : IDENT { rec_typarg(rec_argIdent); rec_newarg(); }
| listarg /* rec_newent lors du ')' */ { rec_newarg(); } | listarg /* rec_newent lors du ')' */ { rec_newarg(); }
| listype listarg /* liste typee */ { rec_newarg(); } | listype listarg /* liste typee */ { rec_newarg(); }
| error { rec_typarg(rec_argMisc); rec_newarg(); | error { rec_typarg(rec_argMisc); rec_newarg();
yyerrstatus = 1; yyclearin; } yyerrstatus_ = 1; yyclearin; }
/* Erreur sur Parametre : tacher de le noter sans jeter l'Entite */ /* Erreur sur Parametre : tacher de le noter sans jeter l'Entite */
; ;
listype : TYPE listype : TYPE
@@ -97,7 +122,7 @@ deblist : '('
finlist : ')' finlist : ')'
{ if (modeprint > 0) { if (modeprint > 0)
{ printf("Record no : %d -- ",nbrec+1); rec_print(currec); } { printf("Record no : %d -- ",nbrec+1); rec_print(currec); }
rec_newent (); yyerrstatus = 0; } rec_newent (); yyerrstatus_ = 0; }
; ;
listarg : deblist finlist /* liste vide (peut y en avoir) */ listarg : deblist finlist /* liste vide (peut y en avoir) */
| deblist arglist finlist /* liste normale, non vide */ | deblist arglist finlist /* liste normale, non vide */
@@ -146,3 +171,11 @@ entlab : ENTITY
enttype : TYPE enttype : TYPE
{ rec_type (); } { rec_type (); }
; ;
%%
void yy::parser::error(const std::string& m)
{
char newmess[80];
sprintf(newmess, "At line %d : %s", scanner->lineno() + 1, m.c_str());
StepFile_Interrupt(newmess);
}

View File

@@ -23,8 +23,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <iostream>
#include <fstream>
#include "recfile.ph" #include "recfile.ph"
#include <OSD_OpenFile.hxx> #include <OSD_OpenFile.hxx>
#include "scanner.hpp"
/* StepFile_Error.c /* StepFile_Error.c
@@ -41,38 +44,14 @@
continuation a change continuation a change
*/ */
static int lastno; void rec_debfile();
extern int steplineno;
extern void StepFile_Interrupt (char* nomfic); /* rln 13.09.00 port on HP*/
int stepparse(void);
void rec_debfile();
void steprestart(FILE *input_file);
void rec_finfile(); void rec_finfile();
void steperror (char *mess)
{
char newmess[80];
if (steplineno == lastno) return;
lastno = steplineno;
sprintf (newmess,"At line %d, %s",steplineno+1,mess);
/* yysbuf[0] = '\0';
yysptr = yysbuf;
* yylineno = 0; */
StepFile_Interrupt(newmess);
}
/* But de ce mini-programme : appeler yyparse et si besoin preciser un /* But de ce mini-programme : appeler yyparse et si besoin preciser un
fichier d'entree fichier d'entree
StepFile_Error redefinit yyerror pour ne pas stopper (s'y reporter) StepFile_Error redefinit yyerror pour ne pas stopper (s'y reporter)
*/ */
extern FILE* stepin ; /* input de yyparse (executeur de lex-yacc) */
extern int steplineno; /* compteur de ligne lex (pour erreurs) */
/* Designation d'un fichier de lecture /* Designation d'un fichier de lecture
(par defaut, c'est l'entree standard) (par defaut, c'est l'entree standard)
@@ -81,40 +60,31 @@ extern int steplineno; /* compteur de ligne lex (pour erreurs) */
iflag retourne vaut 0 si c'est OK, 1 sinon iflag retourne vaut 0 si c'est OK, 1 sinon
*/ */
FILE* stepread_setinput (char* nomfic) void stepread_setinput(std::ifstream& stream, char* nomfic)
{ {
FILE* newin ; if (strlen(nomfic) == 0) return;
if (strlen(nomfic) == 0) return stepin ; OSD_OpenStream(stream, nomfic, std::ios_base::in | std::ios_base::binary);
newin = OSD_OpenFile(nomfic,"r");
if (newin == NULL) {
return NULL ;
} else {
stepin = newin ; return newin ;
}
} }
void stepread_endinput (FILE* infic, char* nomfic) void stepread_endinput (std::ifstream& stream, char* nomfic)
{ {
if (!infic) return; if (!stream) return;
if (strlen(nomfic) == 0) return; if (strlen(nomfic) == 0) return;
fclose (infic); stream.close();
} }
/* Lecture d'un fichier ia grammaire lex-yacc /* Lecture d'un fichier ia grammaire lex-yacc
Appel : i = stepread() ; i est la valeur retournee par yyparse Appel : i = stepread() ; i est la valeur retournee par yyparse
(0 si OK, 1 si erreur) (0 si OK, 1 si erreur)
*/ */
int stepread () int stepread(std::istream* stream)
{ {
int letat; int letat = 0;
lastno = 0; rec_debfile();
steplineno = 0; yy::scanner scanner(stream);
rec_debfile() ; scanner.yyrestart(stream);
steprestart(stepin); yy::parser parser(&scanner);
letat = stepparse() ; letat = parser.parse();
rec_finfile() ; rec_finfile();
return letat; return letat;
} }
int stepwrap () { return 1; }

View File

@@ -16,18 +16,27 @@
// stepread.h // stepread.h
/* lecture du fichier STEP (par appel a lex+yac) */ /* lecture du fichier STEP (par appel a lex+yac) */
#include <iostream>
extern "C" FILE* stepread_setinput (char* nomfic) ; #ifdef __cplusplus
extern "C" void stepread_endinput (FILE* infic, char* nomfic); extern "C" {
extern "C" int stepread() ; #endif
extern "C" void recfile_modeprint (int mode) ; /* controle trace recfile */
void recfile_modeprint (int mode) ; /* controle trace recfile */
/* creation du Direc a partir de recfile : entrys connues de c++ */ /* creation du Direc a partir de recfile : entrys connues de c++ */
extern "C" void lir_file_nbr(int* nbh, int* nbr, int* nbp) ; void lir_file_nbr(int* nbh, int* nbr, int* nbp) ;
extern "C" int lir_file_rec(char* *ident , char* *type , int* nbarg) ; int lir_file_rec(char* *ident , char* *type , int* nbarg) ;
extern "C" void lir_file_finrec() ; void lir_file_finrec() ;
extern "C" int lir_file_arg(int* type , char* *val) ; int lir_file_arg(int* type , char* *val) ;
extern "C" void lir_file_fin(int mode); void lir_file_fin(int mode);
/* Interruption passant par C++ */ /* Interruption passant par C++ */
extern "C" void StepFile_Interrupt (char* nomfic);
#ifdef __cplusplus
}
#endif
void stepread_setinput(std::ifstream& stream, char* nomfic);
void stepread_endinput (std::ifstream& stream, char* nomfic);
int stepread(std::istream* stream);
void StepFile_Interrupt (char* nomfic);

View File

@@ -78,6 +78,23 @@ Standard_Integer StepSelect_WorkLibrary::ReadFile
return status; return status;
} }
Standard_Integer StepSelect_WorkLibrary::ReadStream
(const Standard_CString name,
std::istream* istream,
Handle(Interface_InterfaceModel)& model,
const Handle(Interface_Protocol)& protocol) const
{
long status = 1;
DeclareAndCast(StepData_Protocol, stepro, protocol);
if (stepro.IsNull()) return 1;
Handle(StepData_StepModel) stepmodel = new StepData_StepModel;
model = stepmodel;
StepFile_ReadTrace(0);
char *pName = (char *)name;
status = StepFile_Read(pName, istream, stepmodel, stepro);
return status;
}
Standard_Boolean StepSelect_WorkLibrary::WriteFile Standard_Boolean StepSelect_WorkLibrary::WriteFile
(IFSelect_ContextWrite& ctx) const (IFSelect_ContextWrite& ctx) const

View File

@@ -58,7 +58,12 @@ public:
//! or lets <mod> "Null" in case of Error //! or lets <mod> "Null" in case of Error
//! Returns 0 if OK, 1 if Read Error, -1 if File not opened //! Returns 0 if OK, 1 if Read Error, -1 if File not opened
Standard_EXPORT Standard_Integer ReadFile (const Standard_CString name, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const Standard_OVERRIDE; Standard_EXPORT Standard_Integer ReadFile (const Standard_CString name, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const Standard_OVERRIDE;
//! Reads a STEP File from stream and returns a STEP Model (into <mod>),
//! or lets <mod> "Null" in case of Error
//! Returns 0 if OK, 1 if Read Error, -1 if File not opened
Standard_EXPORT Standard_Integer ReadStream(const Standard_CString name, std::istream* istream, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const Standard_OVERRIDE;
//! Writes a File from a STEP Model //! Writes a File from a STEP Model
//! Returns False (and writes no file) if <ctx> does not bring a //! Returns False (and writes no file) if <ctx> does not bring a
//! STEP Model //! STEP Model

View File

@@ -122,14 +122,26 @@ Handle(XSControl_WorkSession) XSControl_Reader::WS () const
//purpose : //purpose :
//======================================================================= //=======================================================================
IFSelect_ReturnStatus XSControl_Reader::ReadFile IFSelect_ReturnStatus XSControl_Reader::ReadFile (const Standard_CString filename)
(const Standard_CString filename)
{ {
IFSelect_ReturnStatus stat = thesession->ReadFile(filename); IFSelect_ReturnStatus stat = thesession->ReadFile(filename);
thesession->InitTransferReader(4); thesession->InitTransferReader(4);
return stat; return stat;
} }
//=======================================================================
//function : ReadStream
//purpose :
//=======================================================================
IFSelect_ReturnStatus XSControl_Reader::ReadStream(const Standard_CString filename,
std::istream* istream)
{
IFSelect_ReturnStatus stat = thesession->ReadStream(filename, istream);
thesession->InitTransferReader(4);
return stat;
}
Handle(Interface_InterfaceModel) XSControl_Reader::Model () const Handle(Interface_InterfaceModel) XSControl_Reader::Model () const
{ {

View File

@@ -101,6 +101,10 @@ Standard_EXPORT virtual ~XSControl_Reader() {}
//! Loads a file and returns the read status //! Loads a file and returns the read status
//! Zero for a Model which compies with the Controller //! Zero for a Model which compies with the Controller
Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename); Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename);
//! Loads a file from stream and returns the read status
//! Zero for a Model which compies with the Controller
Standard_EXPORT IFSelect_ReturnStatus ReadStream(const Standard_CString filename, std::istream* istream);
//! Returns the model. It can then be consulted (header, product) //! Returns the model. It can then be consulted (header, product)
Standard_EXPORT Handle(Interface_InterfaceModel) Model() const; Standard_EXPORT Handle(Interface_InterfaceModel) Model() const;