diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-05 00:01:18 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-05 00:01:18 +0000 |
commit | 42995d7bf396933ee60c5f89c354ea89cf13df0d (patch) | |
tree | cfdcea0ac57420e7baf570bfe435e107bb842541 /mcopidl | |
download | arts-42995d7bf396933ee60c5f89c354ea89cf13df0d.tar.gz arts-42995d7bf396933ee60c5f89c354ea89cf13df0d.zip |
Copy of aRts for Trinity modifications
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/dependencies/arts@1070145 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'mcopidl')
-rw-r--r-- | mcopidl/Makefile.am | 19 | ||||
-rw-r--r-- | mcopidl/mcopidl.cc | 2645 | ||||
-rw-r--r-- | mcopidl/namespace.cc | 208 | ||||
-rw-r--r-- | mcopidl/namespace.h | 91 | ||||
-rw-r--r-- | mcopidl/scanner.cc | 2090 | ||||
-rw-r--r-- | mcopidl/scanner.ll | 183 | ||||
-rw-r--r-- | mcopidl/yacc.cc | 1507 | ||||
-rw-r--r-- | mcopidl/yacc.cc.h | 75 | ||||
-rw-r--r-- | mcopidl/yacc.yy | 451 |
9 files changed, 7269 insertions, 0 deletions
diff --git a/mcopidl/Makefile.am b/mcopidl/Makefile.am new file mode 100644 index 0000000..da189e5 --- /dev/null +++ b/mcopidl/Makefile.am @@ -0,0 +1,19 @@ +KDE_CXXFLAGS = $(NOOPT_CXXFLAGS) +INCLUDES = -I$(top_srcdir)/mcop -I$(top_builddir)/mcop $(all_includes) +####### Files + +bin_PROGRAMS = mcopidl + +mcopidl_SOURCES = mcopidl.cc yacc.cc scanner.cc namespace.cc +mcopidl_LDFLAGS = $(all_libraries) +mcopidl_LDADD = ../mcop/libmcop.la $(LIBPTHREAD) +noinst_HEADERS = yacc.cc.h + +mcopidl.o: $(top_srcdir)/mcop/common.h + +####### Build rules + +parser: + cd $(srcdir) && flex -B -8 -oscanner.cc scanner.ll ;\ + bison -d -t -o yacc.cc yacc.yy + diff --git a/mcopidl/mcopidl.cc b/mcopidl/mcopidl.cc new file mode 100644 index 0000000..2f8ff23 --- /dev/null +++ b/mcopidl/mcopidl.cc @@ -0,0 +1,2645 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld, stefan@space.twc.de + Nicolas Brodu, nicolas.brodu@free.fr + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include <cstdlib> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <vector> +#include <list> +#include <stack> +#include <ctype.h> +#include "common.h" +#include "namespace.h" +#include <iostream> + +using namespace std; +using namespace Arts; + +int idl_in_include; +int idl_line_no; +string idl_filename; + +/* + * if we start parsing an include file, we push the name of the file + * and the line number where we left it on the stack for later usage + */ +stack<pair<int,string> > idl_include_stack; + +list<EnumDef> enums; +list<TypeDef> structs; +list<InterfaceDef> interfaces; +list<string> packetTypes; // just an evil hack to get experimental video +list<string> customIncludes; // just an evil hack to get experimental video +list<string> includes; // files to include +list<string> includePath; // path for the includes + +// names that occur in included files -> no code generation +list<string> includedNames; + +ModuleDef module; + +void addEnumTodo( const EnumDef& edef ) +{ + enums.push_back(edef); + + if(idl_in_include) + { + includedNames.push_back(edef.name); + } + else + { + module.enums.push_back(edef); + } +} + +void addStructTodo( const TypeDef& type ) +{ + structs.push_back(type); + + if(idl_in_include) + { + includedNames.push_back(type.name); + } + else + { + module.types.push_back(type); + } +} + +void addInterfaceTodo( const InterfaceDef& iface ) +{ + interfaces.push_back(iface); + + if(idl_in_include) + { + includedNames.push_back(iface.name); + } + else + { + module.interfaces.push_back(iface); + } +} + +bool fromInclude(string name) +{ + list<string>::iterator i; + + for(i=includedNames.begin(); i != includedNames.end();i++) + if(*i == name) return true; + + return false; +} + +void startInclude( const char *line ) +{ + const char *file = "*unknown*"; + char *l = strdup(line); + char *a = strtok(l,"<\""); + if(a) + { + char *b = strtok(0,">\""); + if(b) file = b; + } + + idl_in_include++; + idl_include_stack.push(make_pair(idl_line_no, idl_filename)); + idl_line_no = 0; + idl_filename = file; + free(l); +} + +void endInclude() +{ + assert(!idl_include_stack.empty()); + idl_line_no = idl_include_stack.top().first; + idl_filename = idl_include_stack.top().second; + idl_include_stack.pop(); + + idl_in_include--; +} + +bool isPacketType( string type ) +{ + list<string>::iterator i; + + for(i=packetTypes.begin();i != packetTypes.end(); i++) + if((*i) == type) return true; + + return false; +} + +bool isStruct( string type ) +{ + list<TypeDef>::iterator i; + + for(i=structs.begin();i != structs.end(); i++) + if(i->name == type) return true; + + return false; +} + +bool isEnum( string type ) +{ + list<EnumDef>::iterator i; + + for(i=enums.begin();i != enums.end(); i++) + if(i->name == type) return true; + + return false; +} + +bool isInterface( string type ) +{ + list<InterfaceDef>::iterator i; + + for(i=interfaces.begin();i != interfaces.end(); i++) + if(i->name == type) return true; + + return (type == "object"); +} + +string formatMultiLineString(string s, string indent) +{ + string result = indent+"\""; + string::iterator si = s.begin(); + + int lineLen = 80-indent.size()-6; + int i = 0; + + while(si != s.end()) + { + if(i == lineLen) + { + result += "\"\n" + indent + "\""; + i = 0; + } + + result += *si++; + i++; + } + return result+"\""; +} + +#define MODEL_MEMBER 1 +#define MODEL_ARG 2 +#define MODEL_READ 3 +#define MODEL_REQ_READ 4 +#define MODEL_RES_READ 5 +#define MODEL_WRITE 6 +#define MODEL_REQ_WRITE 7 +#define MODEL_RESULT 8 +#define MODEL_INVOKE 9 +#define MODEL_STREAM 10 +#define MODEL_MSTREAM 11 +#define MODEL_ASTREAM 12 +#define MODEL_AMSTREAM 13 +#define MODEL_ASTREAM_PACKETPTR 14 +#define MODEL_SEQ 1024 + +#define MODEL_MEMBER_SEQ (MODEL_MEMBER|MODEL_SEQ) +#define MODEL_ARG_SEQ (MODEL_ARG|MODEL_SEQ) +#define MODEL_READ_SEQ (MODEL_READ|MODEL_SEQ) +#define MODEL_WRITE_SEQ (MODEL_WRITE|MODEL_SEQ) +#define MODEL_REQ_READ_SEQ (MODEL_REQ_READ|MODEL_SEQ) +#define MODEL_RES_READ_SEQ (MODEL_RES_READ|MODEL_SEQ) +#define MODEL_REQ_WRITE_SEQ (MODEL_REQ_WRITE|MODEL_SEQ) +#define MODEL_RESULT_SEQ (MODEL_RESULT|MODEL_SEQ) +#define MODEL_INVOKE_SEQ (MODEL_INVOKE|MODEL_SEQ) + +/** + * generates a piece of code for the specified type/name + * + * model determines if the code is a parameter declaration, type member + * declaration, write-to-stream code for, read-from-stream code or whatever + * else + */ +string createTypeCode(string type, const string& name, long model, + string indent = "") +{ + string result = ""; + + if(type.length() >= 1 && type[0] == '*') + { + model |= MODEL_SEQ; + type = type.substr(1,type.length()-1); + } + + if(type == "void") + { + if(model==MODEL_RES_READ) + { + result = indent + "if(result) delete result;\n"; + } + else if(model==MODEL_INVOKE) + { + result = indent + name+";\n"; + } + else + { + result = "void"; + } + } + else if(type == "float") + { + if(model==MODEL_MEMBER) result = "float"; + if(model==MODEL_MEMBER_SEQ) result = "std::vector<float>"; + if(model==MODEL_ARG) result = "float"; + if(model==MODEL_ARG_SEQ) result = "const std::vector<float>&"; + if(model==MODEL_RESULT) result = "float"; + if(model==MODEL_RESULT_SEQ) result = "std::vector<float> *"; + if(model==MODEL_STREAM) result = "float *"+name; + if(model==MODEL_MSTREAM) result = "float **"+name; + if(model==MODEL_ASTREAM) result = "Arts::FloatAsyncStream "+name; + if(model==MODEL_AMSTREAM) assert(false); + if(model==MODEL_ASTREAM_PACKETPTR) result = "Arts::DataPacket<float> *"; + if(model==MODEL_READ) + result = name+" = stream.readFloat()"; + if(model==MODEL_READ_SEQ) + result = "stream.readFloatSeq("+name+")"; + if(model==MODEL_RES_READ) + { + result = indent + "if(!result) return 0.0; // error occurred\n"; + result += indent + "float returnCode = result->readFloat();\n"; + result += indent + "delete result;\n"; + result += indent + "return returnCode;\n"; + } + if(model==MODEL_RES_READ_SEQ) + { + result = indent + "std::vector<float> *_returnCode =" + " new std::vector<float>;\n"; + result += indent + "if(!result) return _returnCode; // error occurred\n"; + result += indent + "result->readFloatSeq(*_returnCode);\n"; + result += indent + "delete result;\n"; + result += indent + "return _returnCode;\n"; + } + if(model==MODEL_REQ_READ) + result = indent + "float "+name+" = request->readFloat();\n"; + if(model==MODEL_REQ_READ_SEQ) + result = indent + "std::vector<float> "+name+";\n" + + indent + "request->readFloatSeq("+name+");\n"; + if(model==MODEL_WRITE) + result = "stream.writeFloat("+name+")"; + if(model==MODEL_WRITE_SEQ) + result = "stream.writeFloatSeq("+name+")"; + if(model==MODEL_REQ_WRITE) + result = "request->writeFloat("+name+")"; + if(model==MODEL_REQ_WRITE_SEQ) + result = "request->writeFloatSeq("+name+")"; + if(model==MODEL_INVOKE) + result = indent + "result->writeFloat("+name+");\n"; + if(model==MODEL_INVOKE_SEQ) + { + result = indent + "std::vector<float> *_returnCode = "+name+";\n" + + indent + "result->writeFloatSeq(*_returnCode);\n" + + indent + "delete _returnCode;\n"; + } + } + else if(type == "boolean") + { + if(model==MODEL_MEMBER) result = "bool"; + if(model==MODEL_MEMBER_SEQ) result = "std::vector<bool>"; + if(model==MODEL_ARG) result = "bool"; + if(model==MODEL_ARG_SEQ) result = "const std::vector<bool>&"; + if(model==MODEL_RESULT) result = "bool"; + if(model==MODEL_RESULT_SEQ) result = "std::vector<bool> *"; + if(model==MODEL_READ) + result = name+" = stream.readBool()"; + if(model==MODEL_READ_SEQ) + result = "stream.readBoolSeq("+name+")"; + if(model==MODEL_RES_READ) + { + result = indent + "if(!result) return false; // error occurred\n"; + result += indent + "bool returnCode = result->readBool();\n"; + result += indent + "delete result;\n"; + result += indent + "return returnCode;\n"; + } + if(model==MODEL_RES_READ_SEQ) + { + result = indent + "std::vector<bool> *_returnCode =" + " new std::vector<bool>;\n"; + result += indent + "if(!result) return _returnCode; // error occurred\n"; + result += indent + "result->readBoolSeq(*_returnCode);\n"; + result += indent + "delete result;\n"; + result += indent + "return _returnCode;\n"; + } + if(model==MODEL_REQ_READ) + result = indent + "bool "+name+" = request->readBool();\n"; + if(model==MODEL_REQ_READ_SEQ) + result = indent + "std::vector<bool> "+name+";\n" + + indent + "request->readBoolSeq("+name+");\n"; + if(model==MODEL_WRITE) + result = "stream.writeBool("+name+")"; + if(model==MODEL_WRITE_SEQ) + result = "stream.writeBoolSeq("+name+")"; + if(model==MODEL_REQ_WRITE) + result = "request->writeBool("+name+")"; + if(model==MODEL_REQ_WRITE_SEQ) + result = "request->writeBoolSeq("+name+")"; + if(model==MODEL_INVOKE) + result = indent + "result->writeBool("+name+");\n"; + if(model==MODEL_INVOKE_SEQ) + { + result = indent + "std::vector<bool> *_returnCode = "+name+";\n" + + indent + "result->writeBoolSeq(*_returnCode);\n" + + indent + "delete _returnCode;\n"; + } + } + else if(type == "byte") + { + if(model==MODEL_MEMBER) result = "Arts::mcopbyte"; + if(model==MODEL_MEMBER_SEQ) result = "std::vector<Arts::mcopbyte>"; + if(model==MODEL_ARG) result = "Arts::mcopbyte"; + if(model==MODEL_ARG_SEQ) result = "const std::vector<Arts::mcopbyte>&"; + if(model==MODEL_RESULT) result = "Arts::mcopbyte"; + if(model==MODEL_RESULT_SEQ) result = "std::vector<Arts::mcopbyte> *"; + if(model==MODEL_READ) + result = name+" = stream.readByte()"; + if(model==MODEL_READ_SEQ) + result = "stream.readByteSeq("+name+")"; + if(model==MODEL_RES_READ) + { + result = indent + "if(!result) return 0; // error occurred\n"; + result += indent + "Arts::mcopbyte returnCode = result->readByte();\n"; + result += indent + "delete result;\n"; + result += indent + "return returnCode;\n"; + } + if(model==MODEL_RES_READ_SEQ) + { + result = indent + "std::vector<Arts::mcopbyte> *_returnCode =" + " new std::vector<Arts::mcopbyte>;\n"; + result += indent + "if(!result) return _returnCode; // error occurred\n"; + result += indent + "result->readByteSeq(*_returnCode);\n"; + result += indent + "delete result;\n"; + result += indent + "return _returnCode;\n"; + } + if(model==MODEL_REQ_READ) + result = indent + "Arts::mcopbyte "+name+" = request->readByte();\n"; + if(model==MODEL_REQ_READ_SEQ) + result = indent + "std::vector<Arts::mcopbyte> "+name+";\n" + + indent + "request->readByteSeq("+name+");\n"; + if(model==MODEL_WRITE) + result = "stream.writeByte("+name+")"; + if(model==MODEL_WRITE_SEQ) + result = "stream.writeByteSeq("+name+")"; + if(model==MODEL_REQ_WRITE) + result = "request->writeByte("+name+")"; + if(model==MODEL_REQ_WRITE_SEQ) + result = "request->writeByteSeq("+name+")"; + if(model==MODEL_INVOKE) + result = indent + "result->writeByte("+name+");\n"; + if(model==MODEL_INVOKE_SEQ) + { + result = indent + "std::vector<Arts::mcopbyte> *_returnCode = "+name+";\n" + + indent + "result->writeByteSeq(*_returnCode);\n" + + indent + "delete _returnCode;\n"; + } + if(model==MODEL_ASTREAM) + result = "Arts::ByteAsyncStream "+name; + if(model==MODEL_ASTREAM_PACKETPTR) result = "Arts::DataPacket<Arts::mcopbyte> *"; + } + else if(type == "long") + { + if(model==MODEL_MEMBER) result = "long"; + if(model==MODEL_MEMBER_SEQ) result = "std::vector<long>"; + if(model==MODEL_ARG) result = "long"; + if(model==MODEL_ARG_SEQ) result = "const std::vector<long>&"; + if(model==MODEL_RESULT) result = "long"; + if(model==MODEL_RESULT_SEQ) result = "std::vector<long> *"; + if(model==MODEL_READ) + result = name+" = stream.readLong()"; + if(model==MODEL_READ_SEQ) + result = "stream.readLongSeq("+name+")"; + if(model==MODEL_RES_READ) + { + result = indent + "if(!result) return 0; // error occurred\n"; + result += indent + "long returnCode = result->readLong();\n"; + result += indent + "delete result;\n"; + result += indent + "return returnCode;\n"; + } + if(model==MODEL_RES_READ_SEQ) + { + result = indent + "std::vector<long> *_returnCode =" + " new std::vector<long>;\n"; + result += indent + "if(!result) return _returnCode; // error occurred\n"; + result += indent + "result->readLongSeq(*_returnCode);\n"; + result += indent + "delete result;\n"; + result += indent + "return _returnCode;\n"; + } + if(model==MODEL_REQ_READ) + result = indent + "long "+name+" = request->readLong();\n"; + if(model==MODEL_REQ_READ_SEQ) + result = indent + "std::vector<long> "+name+";\n" + + indent + "request->readLongSeq("+name+");\n"; + if(model==MODEL_WRITE) + result = "stream.writeLong("+name+")"; + if(model==MODEL_WRITE_SEQ) + result = "stream.writeLongSeq("+name+")"; + if(model==MODEL_REQ_WRITE) + result = "request->writeLong("+name+")"; + if(model==MODEL_REQ_WRITE_SEQ) + result = "request->writeLongSeq("+name+")"; + if(model==MODEL_INVOKE) + result = indent + "result->writeLong("+name+");\n"; + if(model==MODEL_INVOKE_SEQ) + { + result = indent + "std::vector<long> *_returnCode = "+name+";\n" + + indent + "result->writeLongSeq(*_returnCode);\n" + + indent + "delete _returnCode;\n"; + } + } else if(type == "string") { + if(model==MODEL_MEMBER) result = "std::string"; + if(model==MODEL_MEMBER_SEQ) result = "std::vector<std::string>"; + if(model==MODEL_ARG) result = "const std::string&"; + if(model==MODEL_ARG_SEQ) result = "const std::vector<std::string>&"; + if(model==MODEL_RESULT) result = "std::string"; + if(model==MODEL_RESULT_SEQ) result = "std::vector<std::string> *"; + if(model==MODEL_READ) + result = "stream.readString("+name+")"; + if(model==MODEL_READ_SEQ) + result = "stream.readStringSeq("+name+")"; + if(model==MODEL_REQ_READ) + { + result = indent + "std::string "+name+";\n" + + indent + "request->readString("+name+");\n"; + } + if(model==MODEL_REQ_READ_SEQ) + result = indent + "std::vector<std::string> "+name+";\n" + + indent + "request->readStringSeq("+name+");\n"; + if(model==MODEL_RES_READ) + { + result = indent + "if(!result) return\"\"; // error occurred\n"; + result += indent + "std::string returnCode;\n"; + result += indent + "result->readString(returnCode);\n"; + result += indent + "delete result;\n"; + result += indent + "return returnCode;\n"; + } + if(model==MODEL_RES_READ_SEQ) + { + result = indent + "std::vector<std::string> *_returnCode =" + " new std::vector<std::string>;\n"; + result += indent + "if(!result) return _returnCode; // error occurred\n"; + result += indent + "result->readStringSeq(*_returnCode);\n"; + result += indent + "delete result;\n"; + result += indent + "return _returnCode;\n"; + } + if(model==MODEL_WRITE) + result = "stream.writeString("+name+")"; + if(model==MODEL_WRITE_SEQ) + result = "stream.writeStringSeq("+name+")"; + if(model==MODEL_REQ_WRITE) + result = "request->writeString("+name+")"; + if(model==MODEL_REQ_WRITE_SEQ) + result = "request->writeStringSeq("+name+")"; + if(model==MODEL_INVOKE) + result = indent + "result->writeString("+name+");\n"; + if(model==MODEL_INVOKE_SEQ) + { + result = indent + "std::vector<std::string> *_returnCode = "+name+";\n" + + indent + "result->writeStringSeq(*_returnCode);\n" + + indent + "delete _returnCode;\n"; + } + } else if(isPacketType(type)) { + if(model==MODEL_ASTREAM) + result = type+"AsyncStream "+name; + if(model==MODEL_ASTREAM_PACKETPTR) result = "Arts::DataPacket<"+type+"> *"; + } else if(isStruct(type)) { + if(model==MODEL_MEMBER) + result = type; + if(model==MODEL_MEMBER_SEQ) + result = "std::vector<"+type+">"; + + if(model==MODEL_ARG) + result = "const "+type+"&"; + if(model==MODEL_ARG_SEQ) + result = "const std::vector<"+type+">&"; + + if(model==MODEL_READ) + result = name+".readType(stream)"; + if(model==MODEL_READ_SEQ) + result = "Arts::readTypeSeq(stream,"+name+")"; + if(model==MODEL_REQ_READ) + result = indent + type+" "+name+"(*request);\n"; + if(model==MODEL_REQ_READ_SEQ) + result = indent + "std::vector<"+type+"> "+name+";\n" + + indent + "Arts::readTypeSeq(*request,"+name+");\n"; + + if(model==MODEL_WRITE) + result = name+".writeType(stream)"; + if(model==MODEL_REQ_WRITE) + result = name+".writeType(*request)"; + if(model==MODEL_WRITE_SEQ) + result = "Arts::writeTypeSeq(stream,"+name+")"; + if(model==MODEL_REQ_WRITE_SEQ) + result = "Arts::writeTypeSeq(*request,"+name+")"; + + if(model==MODEL_INVOKE) + result = indent + type + " _returnCode = "+name+";\n" + + indent + "_returnCode.writeType(*result);\n"; + + if(model==MODEL_INVOKE_SEQ) + { + result = indent + "std::vector<"+type+"> *_returnCode = "+name+";\n" + + indent + "Arts::writeTypeSeq(*result,*_returnCode);\n" + + indent + "delete _returnCode;\n"; + } + if(model==MODEL_RES_READ) + { + result = indent + + "if(!result) return "+type+"(); // error occurred\n"; + result += indent+ type + " _returnCode(*result);\n"; + result += indent + "delete result;\n"; + result += indent + "return _returnCode;\n"; + } + if(model==MODEL_RES_READ_SEQ) + { + result = indent + "std::vector<"+type+"> *_returnCode =" + " new std::vector<"+type+">;\n"; + result += indent + "if(!result) return _returnCode; // error occurred\n"; + result += indent + "Arts::readTypeSeq(*result,*_returnCode);\n"; + result += indent + "delete result;\n"; + result += indent + "return _returnCode;\n"; + } + + if(model==MODEL_RESULT) result = type; + if(model==MODEL_RESULT_SEQ) result = "std::vector<"+type+"> *"; + } else if(isEnum(type)) { + if(model==MODEL_MEMBER) result = type; + if(model==MODEL_MEMBER_SEQ) result = "std::vector<"+type+">"; + if(model==MODEL_ARG) result = type; + if(model==MODEL_ARG_SEQ) result = "const std::vector<"+type+">&"; + if(model==MODEL_RESULT) result = type; + if(model==MODEL_RESULT_SEQ) result = "std::vector<"+type+"> *"; + if(model==MODEL_READ) + result = name+" = ("+type+")stream.readLong()"; + if(model==MODEL_READ_SEQ) + result = "stream.readLongSeq("+name+")"; // TODO + if(model==MODEL_RES_READ) + { + result = indent + + "if(!result) return ("+type+")0; // error occurred\n"; + result += indent + type+" returnCode = ("+ + type+")result->readLong();\n"; + result += indent + "delete result;\n"; + result += indent + "return returnCode;\n"; + } + if(model==MODEL_REQ_READ) + result = indent + + type+" "+name+" = ("+type+")request->readLong();\n"; + if(model==MODEL_WRITE) + result = "stream.writeLong("+name+")"; + if(model==MODEL_WRITE_SEQ) + result = "stream.writeLongSeq("+name+")"; // TODO + if(model==MODEL_REQ_WRITE) + result = "request->writeLong("+name+")"; + if(model==MODEL_INVOKE) + result = indent + "result->writeLong("+name+");\n"; + } else if(isInterface(type)) { + // the "object class" is called Object + if(type == "object") type = "Arts::Object"; + + if(model==MODEL_MEMBER) result = type+"_var"; + if(model==MODEL_MEMBER_SEQ) result = "std::vector<"+type+">"; + if(model==MODEL_ARG) result = type; + if(model==MODEL_ARG_SEQ) result = "const std::vector<"+type+">&"; + if(model==MODEL_RESULT) result = type; + if(model==MODEL_RESULT_SEQ) result = "std::vector<"+type+"> *"; + if(model==MODEL_READ) + result = "Arts::readObject(stream,"+name+")"; + if(model==MODEL_READ_SEQ) + result = "Arts::readObjectSeq(stream,"+name+")"; + if(model==MODEL_RES_READ) + { + result = indent + "if (!result) return "+type+"::null();\n"; // error occurred\n"; + result += indent + type+"_base* returnCode;\n"; + result += indent + "Arts::readObject(*result,returnCode);\n"; + result += indent + "delete result;\n"; + result += indent + "return "+type+"::_from_base(returnCode);\n"; + } + if(model==MODEL_RES_READ_SEQ) + { + result = indent + "std::vector<"+type+"> *_returnCode =" + " new std::vector<"+type+">;\n"; + result += indent + "if(!result) return _returnCode; // error occurred\n"; + result += indent + "Arts::readObjectSeq(*result,*_returnCode);\n"; + result += indent + "delete result;\n"; + result += indent + "return _returnCode;\n"; + } + if(model==MODEL_REQ_READ) + { + result = indent + type +"_base* _temp_"+name+";\n"; + result += indent + "Arts::readObject(*request,_temp_"+name+");\n"; + result += indent + type+" "+name+" = "+type+"::_from_base(_temp_"+name+");\n"; + } + if(model==MODEL_REQ_READ_SEQ) + result = indent + "std::vector<"+type+"> "+name+";\n" + + indent + "Arts::readObjectSeq(*request,"+name+");\n"; + if(model==MODEL_WRITE) + result = "Arts::writeObject(stream,"+name+"._base())"; + if(model==MODEL_WRITE_SEQ) + result = "Arts::writeObjectSeq(stream,"+name+")"; + if(model==MODEL_REQ_WRITE) + result = "Arts::writeObject(*request,"+name+"._base())"; + if(model==MODEL_REQ_WRITE_SEQ) + result = "Arts::writeObjectSeq(*request,"+name+")"; + if(model==MODEL_INVOKE) + { + result = indent + type+" returnCode = "+name+";\n" + + indent + "Arts::writeObject(*result,returnCode._base());\n"; + } + if(model==MODEL_INVOKE_SEQ) + { + result = indent + "std::vector<"+type+"> *_returnCode = "+name+";\n" + + indent + "Arts::writeObjectSeq(*result,*_returnCode);\n" + + indent + "delete _returnCode;\n"; + } + } + else + { + fprintf(stderr,"error: undefined type %s occurred\n",type.c_str()); + exit(1); + } + + if((model & ~MODEL_SEQ) == MODEL_MEMBER + || (model & ~MODEL_SEQ) == MODEL_ARG) + { + result += " "; + result += name; + } + return result; +} + +string buildInheritanceList(const InterfaceDef& interface, const string& append) +{ + vector<string>::const_iterator ii; + string result = ""; + bool first = true; + + for(ii=interface.inheritedInterfaces.begin(); + ii != interface.inheritedInterfaces.end();ii++) + { + if(!first) result += ",\n\t"; else first = false; + result += "virtual public "+*ii+append; + } + + return result; +} + +string mkdef(string prefix) +{ + string result; + + for(unsigned int i=0;i<prefix.length();i++) + result += toupper(prefix[i]); + result += "_H"; + + return result; +} + +const char *generated_disclaimer = + "/* this file was generated by the MCOP idl compiler - DO NOT EDIT */\n\n"; + +FILE *startHeader(string prefix) +{ + string header_name = prefix+".h.new"; + FILE *header = fopen(header_name.c_str(),"w"); + + fprintf(header,"%s", generated_disclaimer); + fprintf(header,"#ifndef %s\n",mkdef(prefix).c_str()); + fprintf(header,"#define %s\n\n",mkdef(prefix).c_str()); + fprintf(header,"#include \"common.h\"\n\n"); + fprintf(header,"#include \"arts_export.h\"\n\n"); + + list<string>::iterator cii; + for(cii=customIncludes.begin(); cii != customIncludes.end(); cii++) + fprintf(header,"#include \"%s\"\n",(*cii).c_str()); + if(!customIncludes.empty()) fprintf(header,"\n"); + + return (header); +} + +void endHeader(FILE *header, string prefix) +{ + fprintf(header,"#endif /* %s */\n",mkdef(prefix).c_str()); + fclose(header); +} + +FILE *startSource(string prefix) +{ + string header_name = prefix+".h"; + string source_name = prefix+".cc.new"; + + FILE *source = fopen(source_name.c_str(),"w"); + fprintf(source,"%s", generated_disclaimer); + fprintf(source,"#include \"%s\"\n\n",header_name.c_str()); + + return source; +} + +void endSource(FILE *source) +{ + fclose(source); +} + +/* moves file BASE.new to BASE, but only if there are any changes. Otherwise + BASE.new is simply removed */ +void moveIfChanged(string base) +{ + string newn = base+".new"; + FILE *oldf = fopen(base.c_str(), "r"); + if (!oldf) { + rename(newn.c_str(), base.c_str()); + return; + } + FILE *newf = fopen(newn.c_str(), "r"); + if (!newf) { + fclose(oldf); + return; + } + bool different = false; + unsigned char *oldb, *newb; + size_t blen = 65536; + oldb = new unsigned char[blen]; + newb = new unsigned char[blen]; + while (1) { + size_t olen = fread(oldb, 1, blen, oldf); + size_t nlen = fread(newb, 1, blen, newf); + if (olen != nlen) { + different = true; + break; + } + if (!olen) break; + if (memcmp(oldb, newb, olen)) { + different = true; + break; + } + if (olen < blen) break; + } + delete [] newb; + delete [] oldb; + fclose(newf); + fclose(oldf); + if (different) { + rename(newn.c_str(), base.c_str()); + } else { + unlink(newn.c_str()); + } +} + +bool haveIncluded(string filename) +{ + list<string>::iterator i; + + for(i = ::includes.begin();i != ::includes.end();i++) + if(*i == filename) return true; + + return false; +} + +void doIncludeHeader(FILE *header) +{ + list<string>::iterator i; + bool done_something = false; + + for(i = ::includes.begin();i != ::includes.end();i++) + { + char *include = strdup((*i).c_str()); + if(strlen(include) >= 4) + { + if(strcmp(&include[strlen(include)-4],".idl") == 0) + { + include[strlen(include)-4] = 0; + if(!done_something) + { + fprintf(header,"// includes of other idl definitions\n"); + done_something = true; + } + fprintf(header,"#include \"%s.h\"\n",include); + } + } + free(include); + } + if(done_something) fprintf(header,"\n"); +} + +void doEnumHeader(FILE *header) +{ + list<EnumDef>::iterator edi; + vector<EnumComponent>::iterator i; + NamespaceHelper nspace(header); + + for(edi = enums.begin();edi != enums.end(); edi++) + { + EnumDef& ed = *edi; + + if(fromInclude(ed.name)) continue; // should come from the include + + nspace.setFromSymbol(ed.name); + string ename = nspace.printableForm(ed.name); + if(ename == "_anonymous_") ename = ""; + + fprintf(header,"enum %s {",ename.c_str()); + int first = 0; + for(i=ed.contents.begin();i != ed.contents.end();i++) + { + if(first != 0) fprintf(header,", "); + first++; + fprintf(header,"%s = %ld",i->name.c_str(),i->value); + } + fprintf(header,"};\n"); + } +} + +void doStructHeader(FILE *header) +{ + list<TypeDef>::iterator csi; + vector<TypeComponent>::iterator i; + NamespaceHelper nspace(header); + + for(csi = structs.begin();csi != structs.end(); csi++) + { + TypeDef& d = *csi; + + if(fromInclude(d.name)) continue; // should come from the include + + nspace.setFromSymbol(d.name.c_str()); + string tname = nspace.printableForm(d.name); + + fprintf(header,"class ARTS_EXPORT %s : public Arts::Type {\n",tname.c_str()); + fprintf(header,"public:\n"); + + /** constructor without arguments **/ + fprintf(header,"\t%s();\n",tname.c_str()); + + /** constructor with arguments **/ + fprintf(header,"\t%s(",tname.c_str()); + int first = 0; + for(i=d.contents.begin();i != d.contents.end();i++) + { + string name = createTypeCode(i->type,"_a_" + i->name,MODEL_ARG); + if(first != 0) fprintf(header,", "); + first++; + fprintf(header,"%s",name.c_str()); + } + fprintf(header,");\n"); + + /** constructor from stream **/ + fprintf(header,"\t%s(Arts::Buffer& stream);\n",tname.c_str()); + + /** copy constructor (from same type) **/ + fprintf(header,"\t%s(const %s& copyType);\n", + tname.c_str(),tname.c_str()); + + /** assignment operator **/ + fprintf(header,"\t%s& operator=(const %s& assignType);\n", + tname.c_str(),tname.c_str()); + + /** data members **/ + for(i=d.contents.begin();i != d.contents.end();i++) + { + string name = createTypeCode(i->type,i->name,MODEL_MEMBER); + fprintf(header,"\t%s;\n",name.c_str()); + } + + fprintf(header,"\n// marshalling functions\n"); + + /** marshalling function for reading from stream **/ + fprintf(header,"\tvoid readType(Arts::Buffer& stream);\n"); + + /** marshalling function for writing to stream **/ + fprintf(header,"\tvoid writeType(Arts::Buffer& stream) const;\n"); + + /** returns the name of the type **/ + fprintf(header, "\tstd::string _typeName() const;\n"); + fprintf(header,"};\n\n"); + } +} + +void doStructSource(FILE *source) +{ + list<TypeDef>::iterator csi; + vector<TypeComponent>::iterator i; + + fprintf(source,"// Implementation\n"); + for(csi = structs.begin();csi != structs.end(); csi++) + { + TypeDef& d = *csi; + + if(fromInclude(d.name)) continue; // should come from the include + + string tname = NamespaceHelper::nameOf(d.name); + + fprintf(source,"%s::%s()\n{\n}\n\n",d.name.c_str(),tname.c_str()); + + fprintf(source,"%s::%s(",d.name.c_str(),tname.c_str()); + int first = 0; + for(i=d.contents.begin();i != d.contents.end();i++) + { + string name = createTypeCode(i->type,"_a_" + i->name,MODEL_ARG); + if(first != 0) fprintf(source,", "); + first++; + fprintf(source,"%s",name.c_str()); + } + fprintf(source,")\n{\n"); + for(i=d.contents.begin();i != d.contents.end();i++) + { + string n = "_a_" + i->name; + fprintf(source,"\tthis->%s = %s;\n",i->name.c_str(),n.c_str()); + } + fprintf(source,"}\n\n"); + + /** constructor from stream **/ + fprintf(source,"%s::%s(Arts::Buffer& stream)\n{\n",d.name.c_str(),tname.c_str()); + fprintf(source,"\treadType(stream);\n"); + fprintf(source,"}\n\n"); + + /** copy constructor **/ + + fprintf(source,"%s::%s(const %s& copyType) : Arts::Type(copyType)\n{\n", + d.name.c_str(),tname.c_str(),d.name.c_str()); + fprintf(source,"\tArts::Buffer buffer;\n"); + fprintf(source,"\tcopyType.writeType(buffer);\n"); + fprintf(source,"\treadType(buffer);\n"); + fprintf(source,"}\n\n"); + + /** assignment operator **/ + fprintf(source,"%s& %s::operator=(const %s& assignType)\n{\n", + d.name.c_str(),d.name.c_str(),d.name.c_str()); + fprintf(source,"\tArts::Buffer buffer;\n"); + fprintf(source,"\tassignType.writeType(buffer);\n"); + fprintf(source,"\treadType(buffer);\n"); + fprintf(source,"\treturn *this;\n"); + fprintf(source,"}\n\n"); + +#if 0 /* not needed if types use vector<Type> instead of vector<Type *> */ + /** virtual destuctor: free type contents **/ + fprintf(source,"%s::~%s()\n{\n",d.name.c_str(),tname.c_str()); + for(i=d->contents.begin();i != d->contents.end();i++) + { + string stype = (*i)->type; + string type = stype.substr(1,stype.length()-1); + if(stype[0] == '*' && isStruct(type)) + { + fprintf(source,"\tfreeTypeSeq(%s);\n",(*i)->name.c_str()); + } + } + fprintf(source,"}\n\n"); +#endif + /** marshalling function for reading from stream **/ + fprintf(source,"void %s::readType(Arts::Buffer& stream)\n{\n",d.name.c_str()); + for(i=d.contents.begin();i != d.contents.end();i++) + { + string code = createTypeCode(i->type,i->name,MODEL_READ); + fprintf(source,"\t%s;\n",code.c_str()); + } + fprintf(source,"}\n\n"); + + /** marshalling function for writing to stream **/ + fprintf(source,"void %s::writeType(Arts::Buffer& stream) const\n{\n",d.name.c_str()); + for(i=d.contents.begin();i != d.contents.end();i++) + { + string code = createTypeCode(i->type,i->name,MODEL_WRITE); + fprintf(source,"\t%s;\n",code.c_str()); + } + fprintf(source,"}\n\n"); + + /** returns the name of the type **/ + fprintf(source,"std::string %s::_typeName() const\n{\n",d.name.c_str()); + fprintf(source,"\treturn \"%s\";\n",d.name.c_str()); + fprintf(source,"}\n\n"); + } +} + +string createReturnCode(const MethodDef& md) +{ + return createTypeCode(md.type,"",MODEL_RESULT,""); +} + +string createParamList(const MethodDef& md) +{ + string result; + int first = 0; + vector<ParamDef>::const_iterator pi; + + for(pi = md.signature.begin(); pi != md.signature.end(); pi++) + { + const ParamDef& pd = *pi; + string p = createTypeCode(pd.type,pd.name,MODEL_ARG,""); + + if(first != 0) result += ", "; + first++; + result += p; + } + return result; +} + +string createCallParamList(const MethodDef& md) +{ + string result; + bool first = true; + vector<ParamDef>::const_iterator pi; + + for(pi = md.signature.begin(); pi != md.signature.end(); pi++) + { + if (!first) result += ", "; + first = false; + result += pi->name; + } + return result; +} + +void createStubCode(FILE *source, string iface, string method, + const MethodDef& md) +{ + string rc = createReturnCode(md); + string params = createParamList(md); + vector<ParamDef>::const_iterator pi; + + Buffer b; + md.writeType(b); + + fprintf(source,"%s %s_stub::%s(%s)\n",rc.c_str(),iface.c_str(), + method.c_str(), params.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\tlong methodID = _lookupMethodFast(\"%s\");\n", + b.toString("method").c_str()); + if(md.flags & methodTwoway) + { + fprintf(source,"\tlong requestID;\n"); + fprintf(source,"\tArts::Buffer *request, *result;\n"); + fprintf(source,"\trequest = Arts::Dispatcher::the()->" + "createRequest(requestID,_objectID,methodID);\n"); + } + else + { + fprintf(source,"\tArts::Buffer *request = Arts::Dispatcher::the()->" + "createOnewayRequest(_objectID,methodID);\n"); + } + + for(pi = md.signature.begin(); pi != md.signature.end(); pi++) + { + const ParamDef& pd = *pi; + string p; + p = createTypeCode(pd.type,pd.name,MODEL_REQ_WRITE); + fprintf(source,"\t%s;\n",p.c_str()); + } + fprintf(source,"\trequest->patchLength();\n"); + fprintf(source,"\t_connection->qSendBuffer(request);\n\n"); + + if(md.flags & methodTwoway) + { + fprintf(source,"\tresult = " + "Arts::Dispatcher::the()->waitForResult(requestID,_connection);\n"); + + fprintf(source,"%s", + createTypeCode(md.type,"",MODEL_RES_READ,"\t").c_str()); + } + fprintf(source,"}\n\n"); +} + +bool haveStreams(const InterfaceDef& d) +{ + vector<AttributeDef>::const_iterator ai; + + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + if(ai->flags & attributeStream) return true; + + return false; +} + +bool haveAsyncStreams(const InterfaceDef& d) +{ + vector<AttributeDef>::const_iterator ai; + + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + if((ai->flags & attributeStream) && (ai->flags & streamAsync)) + return true; + + return false; +} + +string dispatchFunctionName(string interface, long mcount) +{ + char number[20]; + sprintf(number,"%02ld",mcount); + + string nspace = NamespaceHelper::namespaceOf(interface); + for (string::iterator i = nspace.begin(); i != nspace.end(); i++) + if(*i == ':') *i = '_'; + + string iname = NamespaceHelper::nameOf(interface); + + return "_dispatch_" + nspace + "_" + iname + "_" + number; +} + +void createDispatchFunction(FILE *source, long mcount, + const InterfaceDef& d, const MethodDef& md,string name) +{ + /** calculate signature (prevents unused argument warnings) **/ + string signature = "void *object, "; + + if(md.signature.size() == 0) + signature += "Arts::Buffer *"; + else + signature += "Arts::Buffer *request"; + + if(md.flags & methodTwoway) + { + if(md.type == "void") + signature += ", Arts::Buffer *"; + else + signature += ", Arts::Buffer *result"; + } + else + { + if(md.type != "void") + { + cerr << "method " << md.name << " in interface " << d.name << + " is declared oneway, but not void" << endl; + exit(1); + } + } + + fprintf(source,"// %s\n",md.name.c_str()); + fprintf(source,"static void %s(%s)\n", + dispatchFunctionName(d.name,mcount).c_str(), signature.c_str()); + fprintf(source,"{\n"); + + string call = "(("+d.name+"_skel *)object)->"+name + "("; + int first = 1; + vector<ParamDef>::const_iterator pi; + for(pi = md.signature.begin(); pi != md.signature.end(); pi++) + { + const ParamDef& pd = *pi; + string p; + + if(!first) call += ","; + first = 0; + call += pd.name; + p = createTypeCode(pd.type,pd.name,MODEL_REQ_READ, "\t"); + fprintf(source,"%s",p.c_str()); + } + call += ")"; + string invoke = createTypeCode(md.type,call,MODEL_INVOKE,"\t"); + fprintf(source,"%s",invoke.c_str()); + fprintf(source,"}\n\n"); +} + +// generate a list of all parents. There can be repetitions +vector<std::string> allParents(const InterfaceDef& iface) +{ + vector<std::string> ret; + list<InterfaceDef>::iterator interIt; + vector<std::string>::const_iterator si; + // For all inherited interfaces + for (si = iface.inheritedInterfaces.begin(); si != iface.inheritedInterfaces.end(); si++) + { + ret.push_back(*si); + // Find the corresponding interface definition + for (interIt=interfaces.begin(); interIt!=interfaces.end(); interIt++) { + InterfaceDef& parent = *interIt; + if (parent.name == (*si)) { + // Now add this parent's parents + vector<std::string> ppar = allParents(parent); + ret.insert(ret.end(), ppar.begin(), ppar.end()); + break; + } + } + } + return ret; +} + +// generate a list of all parents - without repetitions +vector<string> allParentsUnique(const InterfaceDef& iface) +{ + map<string,bool> done; + vector<string> parents = allParents(iface),result; + vector<string>::iterator i; + + for(i=parents.begin();i!=parents.end();i++) + { + string& name = *i; + if(!done[name]) + { + result.push_back(name); + done[name] = true; + } + } + + return result; +} + +InterfaceDef findInterface(const string& iface) +{ + list<InterfaceDef>::iterator i; + for(i=interfaces.begin();i != interfaces.end(); i++) + { + const InterfaceDef& d = *i; + if(d.name == iface) return d; + } + return InterfaceDef(); +} + +InterfaceDef mergeAllParents(const InterfaceDef& iface) +{ + InterfaceDef result = iface; + + vector<string> parents = allParentsUnique(iface); + vector<string>::iterator pi; + + for(pi = parents.begin(); pi != parents.end(); pi++) + { + string parent = *pi; + + list<InterfaceDef>::iterator i; + for(i=interfaces.begin();i != interfaces.end(); i++) + { + const InterfaceDef& d = *i; + if(d.name == parent) + { + /* merge attributes */ + vector<AttributeDef>::const_iterator ai; + + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + result.attributes.push_back(*ai); + + /* merge methods */ + vector<MethodDef>::const_iterator mi; + + for(mi = d.methods.begin(); mi != d.methods.end(); mi++) + { + result.methods.push_back(*mi); + } + } + } + } + return result; +} + +struct ForwardCode { + bool constructor; + string fullifacename, result, mname, params, callparams; + string baseclass; +}; + +void checkSymbolDefinition(const string& name, const string& type, + const InterfaceDef& where, map<string,string>& defs) +{ + string xwhere = where.name + "::" + name + " ("+type+")"; + string& mapentry = defs[name]; + + if(mapentry.empty()) + { + mapentry = xwhere; + } + else + { + cerr << idl_filename << ": warning: " << xwhere + << " collides with " << mapentry << endl; + } +} + +void doInterfacesHeader(FILE *header) +{ + list<InterfaceDef>::iterator ii; + vector<MethodDef>::iterator mi; + vector<AttributeDef>::iterator ai; + string inherits; + NamespaceHelper nspace(header); + list<ForwardCode> forwardCode; + + /* + * this allows it to the various interfaces as parameters, returncodes + * and attributes even before their declaration + */ + for(ii = interfaces.begin();ii != interfaces.end(); ii++) + { + InterfaceDef& d = *ii; + if(!fromInclude(d.name)) + { + nspace.setFromSymbol(d.name); + fprintf(header,"class %s;\n",nspace.printableForm(d.name).c_str()); + } + } + fprintf(header,"\n"); + + for(ii = interfaces.begin();ii != interfaces.end(); ii++) + { + InterfaceDef& d = *ii; + string iname; + string fullifacename = d.name; + + if(fromInclude(d.name)) continue; // should come from the include + + // create abstract interface + inherits = buildInheritanceList(d,"_base"); + if(inherits.empty()) inherits = "virtual public Arts::Object_base"; + + nspace.setFromSymbol(d.name); + iname = nspace.printableForm(d.name); + + fprintf(header,"class ARTS_EXPORT %s_base : %s {\n",iname.c_str(),inherits.c_str()); + fprintf(header,"public:\n"); + fprintf(header,"\tstatic unsigned long _IID; // interface ID\n\n"); + fprintf(header,"\tstatic %s_base *_create(const std::string& subClass" + " = \"%s\");\n", iname.c_str(),d.name.c_str()); + fprintf(header,"\tstatic %s_base *_fromString(const std::string& objectref);\n", + iname.c_str()); + fprintf(header,"\tstatic %s_base *_fromReference(Arts::ObjectReference ref," + " bool needcopy);\n\n",iname.c_str()); + + fprintf(header,"\tstatic %s_base *_fromDynamicCast(const Arts::Object&" + " object);\n", iname.c_str()); + + /* reference counting: _copy */ + fprintf(header,"\tinline %s_base *_copy() {\n" + "\t\tassert(_refCnt > 0);\n" + "\t\t_refCnt++;\n" + "\t\treturn this;\n" + "\t}\n\n",iname.c_str()); + + // Default I/O info + fprintf(header,"\tvirtual std::vector<std::string> _defaultPortsIn() const;\n"); + fprintf(header,"\tvirtual std::vector<std::string> _defaultPortsOut() const;\n"); + fprintf(header,"\n"); + + // Casting + fprintf(header,"\tvoid *_cast(unsigned long iid);\n\n"); + + /* attributes (not for streams) */ + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + { + AttributeDef& ad = *ai; + string rc = createTypeCode(ad.type,"",MODEL_RESULT); + string pc = createTypeCode(ad.type,"newValue",MODEL_ARG); + + if(ad.flags & attributeAttribute) + { + if(ad.flags & streamOut) /* readable from outside */ + { + fprintf(header,"\tvirtual %s %s() = 0;\n",rc.c_str(), + ad.name.c_str()); + } + if(ad.flags & streamIn) /* writeable from outside */ + { + fprintf(header,"\tvirtual void %s(%s) = 0;\n", + ad.name.c_str(), pc.c_str()); + } + } + } + + /* methods */ + for(mi = d.methods.begin(); mi != d.methods.end(); mi++) + { + MethodDef& md = *mi; + string rc = createReturnCode(md); + string params = createParamList(md); + + fprintf(header,"\tvirtual %s %s(%s) = 0;\n",rc.c_str(), + md.name.c_str(), params.c_str()); + } + fprintf(header,"};\n\n"); + + // create stub + + inherits = buildInheritanceList(d,"_stub"); + if(inherits.empty()) inherits = "virtual public Arts::Object_stub"; + + fprintf(header,"class ARTS_EXPORT %s_stub : virtual public %s_base, %s {\n", + iname.c_str(), iname.c_str(),inherits.c_str()); + fprintf(header,"protected:\n"); + fprintf(header,"\t%s_stub();\n\n",iname.c_str()); + + fprintf(header,"public:\n"); + fprintf(header,"\t%s_stub(Arts::Connection *connection, long objectID);\n\n", + iname.c_str()); + /* attributes (not for streams) */ + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + { + AttributeDef& ad = *ai; + string rc = createTypeCode(ad.type,"",MODEL_RESULT); + string pc = createTypeCode(ad.type,"newValue",MODEL_ARG); + + if(ad.flags & attributeAttribute) + { + if(ad.flags & streamOut) /* readable from outside */ + { + fprintf(header,"\t%s %s();\n",rc.c_str(), + ad.name.c_str()); + } + if(ad.flags & streamIn) /* writeable from outside */ + { + fprintf(header,"\tvoid %s(%s);\n", + ad.name.c_str(), pc.c_str()); + } + } + } + /* methods */ + for(mi = d.methods.begin(); mi != d.methods.end(); mi++) + { + MethodDef& md = *mi; + string rc = createReturnCode(md); + string params = createParamList(md); + + fprintf(header,"\t%s %s(%s);\n",rc.c_str(), + md.name.c_str(), params.c_str()); + } + fprintf(header,"};\n\n"); + + // create skeleton + + inherits = buildInheritanceList(d,"_skel"); + if(inherits.empty()) inherits = "virtual public Arts::Object_skel"; + + fprintf(header,"class ARTS_EXPORT %s_skel : virtual public %s_base," + " %s {\n",iname.c_str(),iname.c_str(),inherits.c_str()); + + bool firstStream = true; + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + { + AttributeDef& ad = *ai; + + if(ad.flags & attributeStream) + { + if(firstStream) + { + fprintf(header,"protected:\n"); + fprintf(header,"\t// variables for streams\n"); + firstStream = false; + } + + /** generate declaration of the variable: multi stream? **/ + string decl; + + if(ad.flags & streamMulti) + { + if(ad.flags & streamAsync) + decl = createTypeCode(ad.type,ad.name,MODEL_AMSTREAM); + else + decl = createTypeCode(ad.type,ad.name,MODEL_MSTREAM); + } + else + { + if(ad.flags & streamAsync) + decl = createTypeCode(ad.type,ad.name,MODEL_ASTREAM); + else + decl = createTypeCode(ad.type,ad.name,MODEL_STREAM); + } + + decl += ";"; + + /** write to source **/ + string comment; + + if(ad.flags & streamIn) comment = "incoming stream"; + if(ad.flags & streamOut) comment = "outgoing stream"; + + fprintf(header,"\t%-40s // %s\n",decl.c_str(),comment.c_str()); + } + } + if(!firstStream) fprintf(header,"\n"); + + bool haveAsyncStreams = false; + + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + { + AttributeDef& ad = *ai; + + if((ad.flags & attributeStream) && (ad.flags & streamAsync)) + { + if(!haveAsyncStreams) + { + fprintf(header,"\t// handler for asynchronous streams\n"); + haveAsyncStreams = true; + } + + string ptype = + createTypeCode(ad.type,"",MODEL_ASTREAM_PACKETPTR); + + if(ad.flags & streamIn) + { + fprintf(header,"\tvirtual void process_%s(%s) = 0;\n", + ad.name.c_str(),ptype.c_str()); + } + else + { + fprintf(header,"\tvirtual void request_%s(%s);\n", + ad.name.c_str(),ptype.c_str()); + } + } + } + if(haveAsyncStreams) fprintf(header,"\n"); + + bool haveChangeNotifications = false; + + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + { + AttributeDef& ad = *ai; + + if((ad.flags & attributeAttribute) && (ad.flags & streamOut) + && (ad.type == "byte" || ad.type == "float" || ad.type == "long" + || ad.type == "string" || ad.type == "boolean" + || ad.type == "*byte" || ad.type == "*float" || ad.type == "*long" + || ad.type == "*string" || isEnum(ad.type))) + { + if(!haveChangeNotifications) + { + fprintf(header,"protected:\n"); + fprintf(header,"\t// emitters for change notifications\n"); + haveChangeNotifications = true; + } + + string pc = createTypeCode(ad.type,"newValue",MODEL_ARG); + + fprintf(header,"\tinline void %s_changed(%s) {\n", + ad.name.c_str(),pc.c_str()); + fprintf(header,"\t\t_emit_changed(\"%s_changed\",newValue);\n", + ad.name.c_str()); + fprintf(header,"\t}\n"); + } + } + if(haveChangeNotifications) fprintf(header,"\n"); + + fprintf(header,"public:\n"); + fprintf(header,"\t%s_skel();\n\n",iname.c_str()); + + fprintf(header,"\tstatic std::string _interfaceNameSkel();\n"); + fprintf(header,"\tstd::string _interfaceName();\n"); + fprintf(header,"\tbool _isCompatibleWith(const std::string& interfacename);\n"); + fprintf(header,"\tvoid _buildMethodTable();\n"); + fprintf(header,"\tvoid dispatch(Arts::Buffer *request, Arts::Buffer *result," + "long methodID);\n"); + + if(haveAsyncStreams) + fprintf(header,"\tvoid notify(const Arts::Notification& notification);\n"); + + fprintf(header,"};\n\n"); + + nspace.leaveAll(); + + // Create object wrapper for easy C++ syntax + + fprintf(header,"#include \"reference.h\"\n"); + + // Allow connect facility only if there is something to connect to! +/* if (haveStreams(d)) { + fprintf(header,"#include \"flowsystem.h\"\n"); + } + fprintf(header,"\n"); +*/ + nspace.setFromSymbol(d.name); + + inherits = ": public Arts::Object"; + + fprintf(header,"class ARTS_EXPORT %s %s {\n",iname.c_str(),inherits.c_str()); + fprintf(header,"private:\n"); + fprintf(header,"\tstatic Arts::Object_base* _Creator();\n"); + fprintf(header,"\t%s_base *_cache;\n",iname.c_str()); + fprintf(header,"\tinline %s_base *_method_call() {\n",iname.c_str()); + fprintf(header,"\t\t_pool->checkcreate();\n"); + fprintf(header,"\t\tif(_pool->base) {\n"); + fprintf(header,"\t\t\t_cache=" + "(%s_base *)_pool->base->_cast(%s_base::_IID);\n", + iname.c_str(),iname.c_str()); + fprintf(header,"\t\t\tassert(_cache);\n"); + fprintf(header,"\t\t}\n"); + fprintf(header,"\t\treturn _cache;\n"); + fprintf(header,"\t}\n"); + + // This constructor is now protected. use ::null() and ::_from_base() + // if necessary. It is protected, though there should be noinherited + // class + fprintf(header,"\nprotected:\n"); + fprintf(header,"\tinline %s(%s_base* b) : Arts::Object(b), _cache(0) {}\n\n", + iname.c_str(),iname.c_str()); + + fprintf(header,"\npublic:\n"); + fprintf(header,"\ttypedef %s_base _base_class;\n\n",iname.c_str()); + // empty constructor: specify creator for create-on-demand + fprintf(header,"\tinline %s() : Arts::Object(_Creator), _cache(0) {}\n",iname.c_str()); + + // constructors from reference and for subclass + fprintf(header,"\tinline %s(const Arts::SubClass& s) :\n" + "\t\tArts::Object(%s_base::_create(s.string())), _cache(0) {}\n", + iname.c_str(),iname.c_str()); + fprintf(header,"\tinline %s(const Arts::Reference &r) :\n" + "\t\tArts::Object(" + "r.isString()?(%s_base::_fromString(r.string())):" + "(%s_base::_fromReference(r.reference(),true))), _cache(0) {}\n", + iname.c_str(),iname.c_str(), iname.c_str()); + fprintf(header,"\tinline %s(const Arts::DynamicCast& c) : " + "Arts::Object(%s_base::_fromDynamicCast(c.object())), " + "_cache(0) {}\n", iname.c_str(),iname.c_str()); + + // copy constructors + fprintf(header,"\tinline %s(const %s& target) : Arts::Object(target._pool), _cache(target._cache) {}\n", + iname.c_str(),iname.c_str()); + fprintf(header,"\tinline %s(Arts::Object::Pool& p) : Arts::Object(p), _cache(0) {}\n", + iname.c_str()); + + // null object + // %s::null() returns a null object (and not just a reference to one) + fprintf(header,"\tinline static %s null() {return %s((%s_base*)0);}\n", + iname.c_str(),iname.c_str(),iname.c_str()); + fprintf(header,"\tinline static %s _from_base(%s_base* b) {return %s(b);}\n", + iname.c_str(),iname.c_str(),iname.c_str()); + + // copy operator. + fprintf(header,"\tinline %s& operator=(const %s& target) {\n", + iname.c_str(),iname.c_str()); + // test for equality + fprintf(header,"\t\tif (_pool == target._pool) return *this;\n"); + fprintf(header,"\t\t_pool->Dec();\n"); + fprintf(header,"\t\t_pool = target._pool;\n"); + fprintf(header,"\t\t_cache = target._cache;\n"); + fprintf(header,"\t\t_pool->Inc();\n"); + fprintf(header,"\t\treturn *this;\n"); + fprintf(header,"\t}\n"); + + // casts to parent interfaces + vector<string> parents = allParentsUnique(d); + for (vector<std::string>::iterator si = parents.begin(); + si != parents.end(); si++) + { + string &s = *si; + fprintf(header,"\tinline operator %s() const { return %s(*_pool); }\n", + s.c_str(), s.c_str()); + } + + // conversion to _base* object + fprintf(header,"\tinline %s_base* _base() {return _cache?_cache:_method_call();}\n",iname.c_str()); + fprintf(header,"\n"); + + vector<string> all = parents; + vector<string>::iterator i; + all.push_back(d.name); + // InterfaceDef allMerged = mergeAllParents(d); + + map<string, string> definitionMap; + + for(i=all.begin();i != all.end();i++) + { + InterfaceDef id = findInterface(*i); + string baseclass = id.name+"_base"; + + /* attributes */ + for(ai = id.attributes.begin();ai != id.attributes.end();ai++) + { + AttributeDef& ad = *ai; + ForwardCode fc; + fc.fullifacename = fullifacename; + fc.constructor = false; + fc.mname = ad.name; + fc.baseclass = baseclass; + + checkSymbolDefinition(ad.name, "attribute", id, definitionMap); + + if(ad.flags & attributeAttribute) + { + if(ad.flags & streamOut) /* readable from outside */ + { + fc.params = ""; + fc.callparams = ""; + fc.result = createTypeCode(ad.type,"",MODEL_RESULT); + fprintf(header,"\tinline %s %s();\n", + fc.result.c_str(), fc.mname.c_str()); + forwardCode.push_back(fc); + } + if(ad.flags & streamIn) /* writeable from outside */ + { + fc.params = + createTypeCode(ad.type,"_newValue",MODEL_ARG); + fc.callparams = "_newValue"; + fc.result="void"; + fprintf(header,"\tinline void %s(%s);\n", + fc.mname.c_str(), fc.params.c_str()); + forwardCode.push_back(fc); + } + } + } + + /* methods */ + for(mi = id.methods.begin(); mi != id.methods.end(); mi++) + { + MethodDef& md = *mi; + ForwardCode fc; + fc.fullifacename = fullifacename; + fc.result = createReturnCode(md); + fc.params = createParamList(md); + fc.callparams = createCallParamList(md); + fc.constructor = (md.name == "constructor"); + fc.baseclass = baseclass; + + checkSymbolDefinition(md.name, "method", id, definitionMap); + + // map constructor methods to the real things + if (md.name == "constructor") { + fc.mname = iname; + fprintf(header,"\tinline %s(%s);\n", + iname.c_str(),fc.params.c_str()); + } else { + fc.mname = md.name; + fprintf(header,"\tinline %s %s(%s);\n",fc.result.c_str(), + md.name.c_str(),fc.params.c_str()); + } + + forwardCode.push_back(fc); + } + } + fprintf(header,"};\n\n"); + } + + nspace.leaveAll(); + + /* + * Forwarding code. We have to do this here, as the classes may depend on + * each other, e.g. an argument of one function are a SmartWrapper which is + * declared later in the text. + */ + if(!forwardCode.empty()) + fprintf(header,"// Forward wrapper calls to _base classes:\n\n"); + + list<ForwardCode>::iterator fi; + for(fi = forwardCode.begin(); fi != forwardCode.end(); fi++) + { + if(fi->constructor) + { + fprintf(header,"inline %s::%s(%s)\n", fi->fullifacename.c_str(), + fi->mname.c_str(), fi->params.c_str()); + fprintf(header,"\t\t: Arts::Object(%s_base::_create())\n", + fi->mname.c_str()); + fprintf(header,"{\n"); + fprintf(header,"\tstatic_cast<%s*>(_method_call())->constructor(%s);\n", + fi->baseclass.c_str(),fi->callparams.c_str()); + fprintf(header,"}\n\n"); + } + else + { + fprintf(header,"inline %s %s::%s(%s)\n", + fi->result.c_str(), fi->fullifacename.c_str(), + fi->mname.c_str(), fi->params.c_str()); + fprintf(header,"{\n"); + fprintf(header,"\t%s _cache?static_cast<%s*>(_cache)->%s(%s):" + "static_cast<%s*>(_method_call())->%s(%s);\n", + fi->result=="void"?"":"return", + fi->baseclass.c_str(), + fi->mname.c_str(),fi->callparams.c_str(), + fi->baseclass.c_str(), + fi->mname.c_str(),fi->callparams.c_str()); + + fprintf(header,"}\n\n"); + } + } +} + +enum DefaultDirection {defaultIn, defaultOut}; +bool addParentDefaults(InterfaceDef& iface, vector<std::string>& ports, DefaultDirection dir); +bool lookupParentPort(InterfaceDef& iface, string port, vector<std::string>& ports, DefaultDirection dir); + +bool addDefaults(InterfaceDef& iface, vector<std::string>& ports, DefaultDirection dir) +{ + vector<AttributeDef>::iterator ai; + vector<std::string>::iterator di; + bool hasDefault = false; + // Go through the default ports of this interface + for (di = iface.defaultPorts.begin(); di != iface.defaultPorts.end(); di++) { + bool foundIn = false, foundOut = false; + // Find the corresponding attribute definition + for (ai = iface.attributes.begin(); ai != iface.attributes.end(); ai++) + { + AttributeDef& ad = *ai; + + if ((ad.flags & attributeStream) && ((*di)==ad.name)) { + // Add this port to the list + if (ad.flags & streamIn) { + foundIn=true; + if (dir==defaultIn) ports.push_back(*di); + } + // Add this port to the list + if (ad.flags & streamOut) { + foundOut=true; + if (dir==defaultOut) ports.push_back(*di); + } + } + } + bool found = false; + // Not found, might come from a parent + if (!(foundIn || foundOut)) { + found = lookupParentPort(iface, *di, ports, dir); + } + if ((found) || (foundIn && (dir==defaultIn)) || (foundOut && (dir==defaultOut))) + hasDefault = true; + } + // If no default was specified, then try to inherit some + if (!hasDefault) + hasDefault = addParentDefaults(iface, ports, dir); + + // Still have no default? + // If we have only one stream in a given direction, make it default. + if (!hasDefault) { + vector<AttributeDef>::iterator foundPos; + int found = 0; + for (ai = iface.attributes.begin(); ai != iface.attributes.end(); ai++) + { + AttributeDef& ad = *ai; + if (ad.flags & attributeStream) { + if ((ad.flags & streamIn) && (dir == defaultIn)) { + found++; foundPos=ai; + } + if ((ad.flags & streamOut) && (dir == defaultOut)) { + found++; foundPos=ai; + } + } + } + if (found == 1) {hasDefault=true; ports.push_back(foundPos->name);} + } + return hasDefault; +} + + +bool addParentDefaults(InterfaceDef& iface, vector<std::string>& ports, DefaultDirection dir) +{ + list<InterfaceDef>::iterator interIt; + vector<std::string>::iterator si; + bool hasDefault = false; + // For all inherited interfaces + for (si = iface.inheritedInterfaces.begin(); si != iface.inheritedInterfaces.end(); si++) + { + // Find the corresponding interface definition + for (interIt=interfaces.begin(); interIt!=interfaces.end(); interIt++) { + InterfaceDef& parent = *interIt; + if (parent.name == (*si)) { + // Now add the default ports of this parent + bool b = addDefaults(parent, ports, dir); + if (b) hasDefault = true; + break; + } + } + } + return hasDefault; +} + +bool lookupParentPort(InterfaceDef& iface, string port, vector<std::string>& ports, DefaultDirection dir) +{ + list<InterfaceDef>::iterator interIt; + vector<AttributeDef>::iterator ai; + vector<std::string>::iterator si; + // For all inherited interfaces + for (si = iface.inheritedInterfaces.begin(); si != iface.inheritedInterfaces.end(); si++) + { + // Find the corresponding interface definition + for (interIt=interfaces.begin(); interIt!=interfaces.end(); interIt++) { + InterfaceDef& parent = *interIt; + if (parent.name == (*si)) { + // Now look at the ports of this parent + vector<AttributeDef>::iterator foundPos; + bool found = false; + for (ai = parent.attributes.begin(); ai != parent.attributes.end(); ai++) { + if ((ai->flags & attributeStream) && (ai->name==port)){ + if (((ai->flags & streamIn) && (dir == defaultIn)) + || ((ai->flags & streamOut) && (dir == defaultOut))) { + found = true; foundPos=ai; break; + } + } + } + if (found) {ports.push_back(port); return true;} + // Not found, look recursively at the parent ancestors + bool b = lookupParentPort(parent, port, ports, dir); + if (b) return true; // done + break; + } + } + } + return false; +} + +void doInterfacesSource(FILE *source) +{ + list<InterfaceDef>::iterator ii; + vector<MethodDef>::iterator mi; + vector<AttributeDef>::iterator ai; + + long mcount; + + for(ii = interfaces.begin();ii != interfaces.end(); ii++) + { + InterfaceDef& d = *ii; + + if(fromInclude(d.name)) continue; // should come from the include + + string iname = NamespaceHelper::nameOf(d.name); + + // create static functions + + fprintf(source,"%s_base *%s_base::_create(const std::string& subClass)\n", + d.name.c_str(),d.name.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\tArts::Object_skel *skel = " + "Arts::ObjectManager::the()->create(subClass);\n"); + fprintf(source,"\tassert(skel);\n"); + fprintf(source,"\t%s_base *castedObject = " + "(%s_base *)skel->_cast(%s_base::_IID);\n", + d.name.c_str(),d.name.c_str(),d.name.c_str()); + fprintf(source,"\tassert(castedObject);\n"); + fprintf(source,"\treturn castedObject;\n"); + fprintf(source,"}\n\n"); + + + fprintf(source,"%s_base *%s_base::_fromString(const std::string& objectref)\n", + d.name.c_str(),d.name.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\tArts::ObjectReference r;\n\n"); + fprintf(source,"\tif(Arts::Dispatcher::the()->stringToObjectReference(r,objectref))\n"); + fprintf(source,"\t\treturn %s_base::_fromReference(r,true);\n", + d.name.c_str()); + fprintf(source,"\treturn 0;\n"); + fprintf(source,"}\n\n"); + + fprintf(source,"%s_base *%s_base::_fromDynamicCast(const Arts::Object& object)\n", + d.name.c_str(),d.name.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\tif(object.isNull()) return 0;\n\n"); + fprintf(source,"\t%s_base *castedObject = (%s_base *)object._base()->_cast(%s_base::_IID);\n", + d.name.c_str(), d.name.c_str(), d.name.c_str()); + fprintf(source,"\tif(castedObject) return castedObject->_copy();\n\n"); + fprintf(source,"\treturn _fromString(object._toString());\n"); + fprintf(source,"}\n\n"); + + fprintf(source,"%s_base *%s_base::_fromReference(Arts::ObjectReference r," + " bool needcopy)\n",d.name.c_str(),d.name.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\t%s_base *result;\n",d.name.c_str()); + fprintf(source, + "\tresult = (%s_base *)Arts::Dispatcher::the()->connectObjectLocal(r,\"%s\");\n", + d.name.c_str(),d.name.c_str()); + fprintf(source,"\tif(result)\n"); + fprintf(source,"\t{\n"); + fprintf(source,"\t\tif(!needcopy)\n"); + fprintf(source,"\t\t\tresult->_cancelCopyRemote();\n"); + fprintf(source,"\t}\n"); + fprintf(source,"\telse\n"); + fprintf(source,"\t{\n"); + fprintf(source,"\t\tArts::Connection *conn = " + "Arts::Dispatcher::the()->connectObjectRemote(r);\n"); + fprintf(source,"\t\tif(conn)\n"); + fprintf(source,"\t\t{\n"); + fprintf(source,"\t\t\tresult = new %s_stub(conn,r.objectID);\n", + d.name.c_str()); + fprintf(source,"\t\t\tif(needcopy) result->_copyRemote();\n"); + fprintf(source,"\t\t\tresult->_useRemote();\n"); + + // Type checking + /* + * One may wonder why we first claim that we want to use the object + * using _useRemote, then check if we *can* to use it (if the + * type is right), and finally, if we can't release it + * again. + * + * However, if we don't, we can't release it either, as we may not + * release an object which we don't use. If we would not call release, + * we would on the other hand create a *local* memory leak, as the + * _stub wouldn't get removed. + */ + fprintf(source,"\t\t\tif (!result->_isCompatibleWith(\"%s\")) {\n", + d.name.c_str()); + fprintf(source,"\t\t\t\tresult->_release();\n"); + fprintf(source,"\t\t\t\treturn 0;\n"); + fprintf(source,"\t\t\t}\n"); + + fprintf(source,"\t\t}\n"); + fprintf(source,"\t}\n"); + fprintf(source,"\treturn result;\n"); + fprintf(source,"}\n\n"); + + + // Default I/O info + vector<std::string> portsIn, portsOut; + vector<std::string>::iterator si, di; + addDefaults(d, portsIn, defaultIn); + addDefaults(d, portsOut, defaultOut); + + vector<std::string> done; // don't repeat values + fprintf(source,"std::vector<std::string> %s_base::_defaultPortsIn() const {\n",d.name.c_str()); + fprintf(source,"\tstd::vector<std::string> ret;\n"); + // Loop through all the values + for (si = portsIn.begin(); si != portsIn.end(); si++) + { + // repeated value? (virtual public like merging...) + bool skipIt = false; + for (di = done.begin(); di != done.end(); di++) { + if ((*di)==(*si)) {skipIt = true; break;} + } + if (skipIt) continue; + fprintf(source,"\tret.push_back(\"%s\");\n",(*si).c_str()); + done.push_back(*si); + } + fprintf(source,"\treturn ret;\n}\n"); + done.clear(); + fprintf(source,"std::vector<std::string> %s_base::_defaultPortsOut() const {\n",d.name.c_str()); + fprintf(source,"\tstd::vector<std::string> ret;\n"); + // Loop through all the values + for (si = portsOut.begin(); si != portsOut.end(); si++) + { + // repeated value? (virtual public like merging...) + bool skipIt = false; + for (di = done.begin(); di != done.end(); di++) { + if ((*di)==(*si)) {skipIt = true; break;} + } + if (skipIt) continue; + fprintf(source,"\tret.push_back(\"%s\");\n",(*si).c_str()); + done.push_back(*si); + } + fprintf(source,"\treturn ret;\n}\n\n"); + + /** _cast operation **/ + vector<std::string> parentCast = allParentsUnique(d); + + fprintf(source,"void *%s_base::_cast(unsigned long iid)\n", + d.name.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\tif(iid == %s_base::_IID) return (%s_base *)this;\n", + d.name.c_str(),d.name.c_str()); + + vector<std::string>::iterator pci; + for(pci = parentCast.begin(); pci != parentCast.end();pci++) + { + string& pc = *pci; + fprintf(source,"\tif(iid == %s_base::_IID) " + "return (%s_base *)this;\n",pc.c_str(),pc.c_str()); + } + fprintf(source,"\tif(iid == Arts::Object_base::_IID) return (Arts::Object_base *)this;\n"); + fprintf(source,"\treturn 0;\n"); + fprintf(source,"}\n\n"); + + // create stub + + /** constructors **/ + fprintf(source,"%s_stub::%s_stub()\n" ,d.name.c_str(),iname.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\t// constructor for subclasses" + " (don't use directly)\n"); + fprintf(source,"}\n\n"); + + fprintf(source,"%s_stub::%s_stub(Arts::Connection *connection, " + "long objectID)\n",d.name.c_str(),iname.c_str()); + fprintf(source," : Arts::Object_stub(connection, objectID)\n"); + fprintf(source,"{\n"); + fprintf(source,"\t// constructor to create a stub for an object\n"); + fprintf(source,"}\n\n"); + + /** stub operations **/ + + /** stub operations for object methods **/ + for(mi = d.methods.begin(); mi != d.methods.end(); mi++) + { + MethodDef& md = *mi; + createStubCode(source,d.name.c_str(),md.name.c_str(),md); + } + + /** stub operations for attributes **/ + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + { + AttributeDef& ad = *ai; + + if(ad.flags & attributeAttribute) + { + MethodDef md; + if(ad.flags & streamOut) /* readable from outside */ + { + md.name = "_get_"+ad.name; + md.type = ad.type; + md.flags = methodTwoway; + /* no parameters (don't set md.signature) */ + + createStubCode(source,d.name.c_str(),ad.name.c_str(),md); + } + if(ad.flags & streamIn) /* writeable from outside */ + { + md.name = "_set_"+ad.name; + md.type = "void"; + md.flags = methodTwoway; + + ParamDef pd; + pd.type = ad.type; + pd.name = "newValue"; + md.signature.push_back(pd); + + createStubCode(source,d.name.c_str(),ad.name.c_str(),md); + } + } + } + + // create skeleton + + /** _interfaceName **/ + fprintf(source,"std::string %s_skel::_interfaceName()\n", + d.name.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\treturn \"%s\";\n",d.name.c_str()); + fprintf(source,"}\n\n"); + + // Run-time type compatibility check + fprintf(source,"bool %s_skel::_isCompatibleWith(const std::string& interfacename)\n", + d.name.c_str()); + fprintf(source,"{\n"); + // Interface is compatible with itself! + fprintf(source,"\tif (interfacename == \"%s\") return true;\n",d.name.c_str()); + // It also provides the parent interfaces + for(pci = parentCast.begin(); pci != parentCast.end();pci++) + { + fprintf(source,"\tif (interfacename == \"%s\") return true;\n", pci->c_str()); + } + // and is ultimately an Object + fprintf(source,"\tif (interfacename == \"Arts::Object\") return true;\n"); + fprintf(source,"\treturn false;\n"); // And nothing else + fprintf(source,"}\n\n"); + + fprintf(source,"std::string %s_skel::_interfaceNameSkel()\n", + d.name.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\treturn \"%s\";\n",d.name.c_str()); + fprintf(source,"}\n\n"); + + /** dispatch operations **/ + Buffer methodTable; + + /** dispatch operations for object methods **/ + mcount = 0; + for(mi = d.methods.begin(); mi != d.methods.end(); mi++, mcount++) + { + MethodDef& md = *mi; + md.writeType(methodTable); + + createDispatchFunction(source,mcount,d,md,md.name); + } + + /** dispatch operations for attributes **/ + + for(ai = d.attributes.begin();ai != d.attributes.end();ai++) + { + AttributeDef& ad = *ai; + + if(ad.flags & attributeAttribute) + { + MethodDef md; + if(ad.flags & streamOut) /* readable from outside */ + { + md.name = "_get_"+ad.name; + md.type = ad.type; + md.flags = methodTwoway; + /* no parameters (don't set md.signature) */ + + md.writeType(methodTable); + createDispatchFunction(source,mcount++,d,md,ad.name); + } + if(ad.flags & streamIn) /* writeable from outside */ + { + md.name = "_set_"+ad.name; + md.type = "void"; + md.flags = methodTwoway; + + ParamDef pd; + pd.type = ad.type; + pd.name = "newValue"; + + md.signature.push_back(pd); + + md.writeType(methodTable); + createDispatchFunction(source,mcount++,d,md,ad.name); + } + } + } + + /** methodTable **/ + + string methodTableString = formatMultiLineString( + methodTable.toString("MethodTable")," "); + + fprintf(source,"void %s_skel::_buildMethodTable()\n",d.name.c_str()); + fprintf(source,"{\n"); + fprintf(source,"\tArts::Buffer m;\n"); + fprintf(source,"\tm.fromString(\n"); + fprintf(source,"%s,\n",methodTableString.c_str()); + fprintf(source,"\t\t\"MethodTable\"\n"); + fprintf(source,"\t);\n"); + + long i; + for(i=0;i<mcount;i++) + fprintf(source,"\t_addMethod(%s,this,Arts::MethodDef(m));\n", + dispatchFunctionName(d.name,i).c_str()); + + vector<string>::iterator ii = d.inheritedInterfaces.begin(); + while(ii != d.inheritedInterfaces.end()) + { + fprintf(source,"\t%s_skel::_buildMethodTable();\n", + ii->c_str()); + ii++; + } + fprintf(source,"}\n\n"); + + fprintf(source,"%s_skel::%s_skel()\n", d.name.c_str(),iname.c_str()); + fprintf(source,"{\n"); + for(ai = d.attributes.begin(); ai != d.attributes.end(); ai++) + { + AttributeDef& ad = *ai; + if((ad.flags & attributeStream) == attributeStream) + { + fprintf(source,"\t_initStream(\"%s\",&%s,%d);\n", + ad.name.c_str(),ad.name.c_str(),ad.flags); + } + } + fprintf(source,"}\n\n"); + + /** notification operation **/ + if(haveAsyncStreams(d)) + { + fprintf(source,"void %s_skel::notify(const Arts::Notification " + "¬ification)\n", d.name.c_str()); + fprintf(source,"{\n"); + for(ai = d.attributes.begin(); ai != d.attributes.end(); ai++) + { + AttributeDef& ad = *ai; + if((ad.flags & (attributeStream|streamAsync)) + == (attributeStream|streamAsync)) + { + const char *fname=(ad.flags&streamIn)?"process":"request"; + string packettype = + createTypeCode(ad.type,"",MODEL_ASTREAM_PACKETPTR); + + fprintf(source,"\tif(%s.notifyID() == notification.ID)\n", + ad.name.c_str()); + fprintf(source, + "\t\t%s_%s((%s)notification.data);\n", + fname,ad.name.c_str(),packettype.c_str()); + } + } + fprintf(source,"}\n\n"); + + /* + * create empty request_ methods for output streams + * (not everybody uses requesting) + */ + for(ai = d.attributes.begin(); ai != d.attributes.end(); ai++) + { + AttributeDef& ad = *ai; + if((ad.flags & (attributeStream|streamAsync|streamOut)) + == (attributeStream|streamAsync|streamOut)) + { + string packettype = + createTypeCode(ad.type,"",MODEL_ASTREAM_PACKETPTR); + fprintf(source,"void %s_skel::request_%s(%s)\n", + d.name.c_str(),ad.name.c_str(),packettype.c_str()); + fprintf(source,"{\n"); + fprintf(source," assert(false); // this default is for " + "modules who don't want requesting\n"); + fprintf(source,"}\n\n"); + } + } + } + + // Smartwrapper statics + // _Creator + fprintf(source,"Arts::Object_base* %s::_Creator() {\n",d.name.c_str()); + fprintf(source,"\treturn %s_base::_create();\n",d.name.c_str()); + fprintf(source,"}\n\n"); + + // IID + fprintf(source,"unsigned long %s_base::_IID = " + "Arts::MCOPUtils::makeIID(\"%s\");\n\n",d.name.c_str(),d.name.c_str()); + } +} + +void doInterfaceRepoSource(FILE *source, string prefix) +{ + Buffer b; + module.moduleName = ""; + module.writeType(b); + + string data = formatMultiLineString(b.toString("IDLFile")," "); + + fprintf(source,"static Arts::IDLFileReg IDLFileReg_%s(\"%s\",\n%s\n);\n", + prefix.c_str(),prefix.c_str(),data.c_str()); +} + +void doTypeFile(string prefix) +{ + Buffer b; + module.moduleName = prefix; + module.writeType(b); + + FILE *typeFile = fopen((prefix+".mcoptype.new").c_str(),"w"); + unsigned long towrite = b.size(); + fwrite(b.read(towrite),1,towrite,typeFile); + fclose(typeFile); +} + +void doTypeIndex(string prefix) +{ + FILE *typeIndex = fopen((prefix+".mcopclass.new").c_str(),"w"); + + vector<string> supportedTypes; + + vector<InterfaceDef>::iterator ii; + for(ii = module.interfaces.begin(); ii != module.interfaces.end(); ii++) + if(!fromInclude(ii->name)) supportedTypes.push_back(ii->name); + + vector<TypeDef>::iterator ti; + for(ti = module.types.begin(); ti != module.types.end(); ti++) + if(!fromInclude(ti->name)) supportedTypes.push_back(ti->name); + + string supportedTypesList; + vector<string>::iterator si; + bool first = true; + for(si = supportedTypes.begin(); si != supportedTypes.end(); si++) + { + if(!first) supportedTypesList += ","; + + supportedTypesList += (*si); + first = false; + } + fprintf(typeIndex, "# this file was generated by the MCOP idl compiler - DO NOT EDIT\n"); + fprintf(typeIndex,"Type=%s\n",supportedTypesList.c_str()); + fprintf(typeIndex,"TypeFile=%s.mcoptype\n",prefix.c_str()); + fclose(typeIndex); +} + +void exit_usage(char *name) +{ + fprintf(stderr,"usage: %s [ <options> ] <filename>\n",name); + fprintf(stderr,"\nOptions:\n"); + fprintf(stderr," -I <directory> search in <directory> for includes\n"); + fprintf(stderr," -e <name> exclude a struct/interface/enum from code generation\n"); + fprintf(stderr," -t create .mcoptype/.mcopclass files with type information\n"); + exit(1); +} +extern void mcopidlParse(const char *code); + +bool match(vector<char>::iterator start, const char *string) +{ + while(*string && *start) + if(*string++ != *start++) return false; + + return (*string == 0); +} + +bool fileExists(const char *filename) +{ + FILE *test = fopen(filename,"r"); + if(test) + { + fclose(test); + return true; + } + return false; +} + +string searchFile(const char *filename,list<string>& path) +{ + if(fileExists(filename)) return filename; + + list<string>::iterator i; + for(i = path.begin(); i != path.end(); i++) + { + string location = *i + "/" + filename; + if(fileExists(location.c_str())) return location; + } + fprintf(stderr,"file '%s' not found\n",filename); + exit(1); +} + +void append_file_to_vector(const char *filename, vector<char>& v) +{ + FILE *f = fopen(filename,"r"); + if(!f) { + fprintf(stderr,"file '%s' not found\n",filename); + exit(1); + } + + char buffer[1024]; + long l; + while((l = fread(buffer,1,1024,f)) > 0) + v.insert(v.end(),buffer, buffer+l); + fclose(f); +} + +void append_string_to_vector(const char *string, vector<char>& v) +{ + while(*string) v.push_back(*string++); +} + +void preprocess(vector<char>& input, vector<char>& output) +{ + string filename; + enum { lineStart, idlCode, commentC, filenameFind, + filenameIn1, filenameIn2 } state = lineStart; + + vector<char>::iterator i = input.begin(); + + while(i != input.end()) + { + if(state != commentC && match(i,"/*")) // check if here starts a comment + { + state = commentC; + i += 2; + } + else if(state == commentC) + { + if(match(i,"*/")) // leave comment state? + { + state = idlCode; + i += 2; + } + else // skip comments + { + if(*i == '\n') output.push_back(*i); // keep line numbering + i++; + } + } + else if(state == filenameFind) + { + switch(*i++) + { + case ' ': // skip whitespaces + case '\t': + break; + + case '"': state = filenameIn1; + break; + case '<': state = filenameIn2; + break; + default: cerr << "bad char after #include statement" << endl; + assert(0); // error handling! + } + } + else if((state == filenameIn1 && *i == '"') + || (state == filenameIn2 && *i == '>')) + { + append_string_to_vector("#startinclude <",output); + append_string_to_vector(filename.c_str(),output); + append_string_to_vector(">\n",output); + + if(!haveIncluded(filename)) + { + ::includes.push_back(filename); + + // load include, preprocess + vector<char> file,filepp; + + string location = searchFile(filename.c_str(),includePath); + append_file_to_vector(location.c_str(),file); + preprocess(file,filepp); + + // append preprocessed file + output.insert(output.end(),filepp.begin(),filepp.end()); + } + + append_string_to_vector("#endinclude",output); + state = idlCode; + i++; + } + else if(state == filenameIn1 || state == filenameIn2) + { + filename += *i++; + } + else if(state == lineStart) // check if we're on lineStart + { + if(match(i,"#include")) + { + i += 8; + state = filenameFind; + filename = ""; + } + else + { + if(*i != ' ' && *i != '\t' && *i != '\n') state = idlCode; + output.push_back(*i++); + } + } + else + { + if(*i == '\n') state = lineStart; // newline handling + output.push_back(*i++); + } + } +} + +int main(int argc, char **argv) +{ + /* + * parse command line options + */ + int c; + bool makeTypeInfo = false; + while((c = getopt(argc, argv, "I:P:C:te:")) != -1) + { + switch(c) + { + case 'I': includePath.push_back(optarg); + break; + case 'P': packetTypes.push_back(optarg); + break; + case 'C': customIncludes.push_back(optarg); + break; + case 't': makeTypeInfo = true; + break; + case 'e': includedNames.push_back(optarg); + break; + default: exit_usage(argv[0]); + break; + } + } + + if((argc-optind) != 1) exit_usage(argv[0]); + + const char *inputfile = argv[optind]; + + /* + * find out prefix (filename without .idl) + */ + + char *prefix = strdup(inputfile); + + if(strlen(prefix) < 4 || strcmp(&prefix[strlen(prefix)-4],".idl")) { + fprintf(stderr,"filename must end in .idl\n"); + exit(1); + } else { + prefix[strlen(prefix)-4] = 0; + } + + /* + * strip path (mcopidl always outputs the result into the current directory) + */ + char *pathless = strrchr(prefix,'/'); + if(pathless) + prefix = pathless+1; + + /* + * load file + */ + + idl_line_no = 1; + idl_in_include = 0; + idl_filename = inputfile; + + vector<char> contents,contentspp; + append_file_to_vector(inputfile,contents); + + // trailing zero byte (mcopidlParse wants a C-style string as argument) + contents.push_back(0); + + // preprocess (throws includes into contents, removes C-style comments) + preprocess(contents,contentspp); + + // call lex&yacc parser + mcopidlParse(&contentspp[0]); + + // generate code for C++ header file + FILE *header = startHeader(prefix); + doIncludeHeader(header); + doEnumHeader(header); + doStructHeader(header); + doInterfacesHeader(header); + endHeader(header,prefix); + moveIfChanged(string(prefix)+".h"); + + // generate code for C++ source file + FILE *source = startSource(prefix); + doStructSource(source); + doInterfacesSource(source); + doInterfaceRepoSource(source,prefix); + endSource(source); + moveIfChanged(string(prefix)+".cc"); + + // create type file + if(makeTypeInfo) + { + doTypeFile(prefix); + doTypeIndex(prefix); + moveIfChanged(string(prefix)+".mcoptype"); + moveIfChanged(string(prefix)+".mcopclass"); + } + + return 0; +} diff --git a/mcopidl/namespace.cc b/mcopidl/namespace.cc new file mode 100644 index 0000000..1e863a0 --- /dev/null +++ b/mcopidl/namespace.cc @@ -0,0 +1,208 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + */ + +#include <string.h> +#include <stdio.h> +#include <list> +#include <string> +#include <map> +#include "namespace.h" +#include <assert.h> + +using namespace std; + +/* generic utilities */ + +static list<string> symbolToList(string symbol) +{ + list<string> result; + string current; + + string::iterator si; + for(si = symbol.begin(); si != symbol.end(); si++) + { + if(*si != ':') + { + current += *si; + } + else + { + if(!current.empty()) + result.push_back(current); + + current = ""; + } + } + + result.push_back(current); + return result; +} + +static string listToSymbol(list<string>& symlist) +{ + string s; + list<string>::iterator si; + for(si = symlist.begin(); si != symlist.end(); si++) + { + if(!s.empty()) s += "::"; + s += *si; + } + return s; +} + +/* ModuleHelper */ +static list<string> modulePath; +static map<string,bool> moduleDefinitions; + +void ModuleHelper::enter(const char *name) +{ + modulePath.push_back(name); +} + +void ModuleHelper::leave() +{ + assert(!modulePath.empty()); + modulePath.pop_back(); +} + +string prependModulePath(string s) +{ + if(modulePath.empty()) + return s; + else + return listToSymbol(modulePath)+"::"+s; +} + +void ModuleHelper::define(const char *name) +{ + moduleDefinitions[prependModulePath(name)] = true; +} + +char *ModuleHelper::qualify(const char *name) +{ + char *result = 0; + + // TODO: nested namespaces + + string inCurrentModule = prependModulePath(name); + if(moduleDefinitions[inCurrentModule]) + { + result = strdup(inCurrentModule.c_str()); + } + else if(moduleDefinitions[name]) + { + result = strdup(name); + } + else + { + fprintf(stderr,"warning: qualifyName failed for %s\n",name); + result = strdup(name); + } + + return result; +} + + +/* NamespaceHelper */ +NamespaceHelper::NamespaceHelper(FILE *outputfile) : out(outputfile) +{ +} + +NamespaceHelper::~NamespaceHelper() +{ + leaveAll(); +} + +void NamespaceHelper::setFromSymbol(string symbol) +{ + list<string> symlist = symbolToList(symbol); + symlist.pop_back(); + + /* check that the current namespace doesn't contain wrong parts at end */ + list<string>::iterator ni,si; + ni = currentNamespace.begin(); + si = symlist.begin(); + long wrong = currentNamespace.size(); + while(ni != currentNamespace.end() && si != symlist.end() && *ni == *si) + { + ni++; + si++; + wrong--; + } + while(wrong--) + { + fprintf(out,"}\n"); + } + + /* enter new components at the end */ + while(si != symlist.end()) + { + fprintf(out,"namespace %s {\n",(*si++).c_str()); + } + currentNamespace = symlist; +} + +void NamespaceHelper::leaveAll() +{ + setFromSymbol("unqualified"); +} + +string NamespaceHelper::printableForm(string symbol) +{ + list<string> symlist = symbolToList(symbol); + list<string> current = currentNamespace; + + while(!current.empty()) + { + // namespace longer than symbol? + assert(!symlist.empty()); + + if(*current.begin() == *symlist.begin()) + { + current.pop_front(); + symlist.pop_front(); + } + else + { + return "::"+symbol; + } + } + + return listToSymbol(symlist); +} + +string NamespaceHelper::nameOf(string symbol) +{ + if(symbol.empty()) return ""; + + list<string> symlist = symbolToList(symbol); + return symlist.back(); +} + +string NamespaceHelper::namespaceOf(string symbol) +{ + list<string> symlist = symbolToList(symbol); + if(symlist.size() < 2) return ""; + + symlist.pop_back(); + return listToSymbol(symlist); +} diff --git a/mcopidl/namespace.h b/mcopidl/namespace.h new file mode 100644 index 0000000..479e30f --- /dev/null +++ b/mcopidl/namespace.h @@ -0,0 +1,91 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + */ +#ifndef _MCOPIDL_NAMESPACE_H__ +#define _MCOPIDL_NAMESPACE_H__ + +#include <stdio.h> +#include <string> +#include <list> + +/** + * This class is used while parsing IDL files. It is used to produce fully + * qualified names (e.g. Arts::Object rather than just Object) of all type + * identifiers. + */ +class ModuleHelper { +public: + static void enter(const char *name); + static void leave(); + static void define(const char *name); + static char *qualify(const char *name); +}; + +/** + * This class is used during code generation. It generates the namespace + * opening and closing code. + */ +class NamespaceHelper { +protected: + FILE *out; + std::list<std::string> currentNamespace; + +public: + NamespaceHelper(FILE *outputfile); + ~NamespaceHelper(); + + /** + * This method will cause the NamespaceHelper to enter the namespace the + * symbol is in. That means setFromSymbol("Arts::Object") will enter the + * namespace Arts. Since this generates code, it should only be called + * outside of class definitions. + */ + void setFromSymbol(std::string symbol); + + /** + * This leaves all open namespaces which is useful if you want to include + * a file or such, or if you are at the end of a file. + */ + void leaveAll(); + + /** + * The shortest printable form of a symbol - using "Arts::Object" as + * example, this would be "Arts::Object", if you are in no namespace, + * ::Arts::Object, if you are in a different namespace, and just Object, + * if you are in the Arts namespace. + */ + std::string printableForm(std::string symbol); + + /** + * Returns only the last component of the symbol (the name) cutting the + * namespace components + */ + static std::string nameOf(std::string symbol); + + /** + * Returns everything but the last component of the symbol, which is + * the namespace (e.g. namespaceOf("Arts::Object") returns Arts, and + * nameOf("Arts::Object") returns Object). + */ + static std::string namespaceOf(std::string symbol); +}; + +#endif diff --git a/mcopidl/scanner.cc b/mcopidl/scanner.cc new file mode 100644 index 0000000..76139f7 --- /dev/null +++ b/mcopidl/scanner.cc @@ -0,0 +1,2090 @@ +#line 2 "scanner.cc" +/* A lexical scanner generated by flex */ + +/* Scanner skeleton version: + */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 + +#include <stdio.h> + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include <stdlib.h> +#include <unistd.h> + +/* Use prototypes in function declarations. */ +#define YY_USE_PROTOS + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#if __STDC__ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + +#ifdef __TURBOC__ + #pragma warn -rch + #pragma warn -use +#include <io.h> +#include <stdlib.h> +#define YY_USE_CONST +#define YY_USE_PROTOS +#endif + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN yy_start = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START ((yy_start - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#define YY_BUF_SIZE 16384 + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +extern int yyleng; +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* The funky do-while in the following #define is used to turn the definition + * int a single C statement (which needs a semi-colon terminator). This + * avoids problems with code like: + * + * if ( condition_holds ) + * yyless( 5 ); + * else + * do_something_else(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the yyless() call. + */ + +/* Return all but the first 'n' matched characters back to the input stream. */ + +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + *yy_cp = yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, yytext_ptr ) + +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ +typedef unsigned int yy_size_t; + + +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + }; + +static YY_BUFFER_STATE yy_current_buffer = 0; + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* 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 ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart YY_PROTO(( FILE *input_file )); + +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); +void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); +#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) + +YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); +YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); +YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); + +static void *yy_flex_alloc YY_PROTO(( yy_size_t )); +static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); +static void yy_flex_free YY_PROTO(( void * )); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) + + +#define YY_USES_REJECT + +#define yywrap() 1 +#define YY_SKIP_YYWRAP +typedef unsigned char YY_CHAR; +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; +typedef int yy_state_type; +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define YY_NUM_RULES 48 +#define YY_END_OF_BUFFER 49 +static yyconst short int yy_acclist[507] = + { 0, + 5, 5, 49, 5, 47, 48, 1, 5, 47, 48, + 2, 48, 5, 47, 48, 5, 12, 47, 48, 5, + 13, 47, 48, 6, 47, 48, 5, 16, 47, 48, + 5, 47, 48, 5, 45, 47, 48, 5, 44, 47, + 48, 5, 18, 47, 48, 5, 17, 47, 48, 5, + 14, 47, 48, 5, 19, 47, 48, 5, 15, 47, + 48, 5, 42, 43, 47, 48, 5, 42, 43, 47, + 48, 5, 42, 43, 47, 48, 5, 42, 43, 47, + 48, 5, 42, 43, 47, 48, 5, 42, 43, 47, + 48, 5, 42, 43, 47, 48, 5, 42, 43, 47, + + 48, 5, 42, 43, 47, 48, 5, 42, 43, 47, + 48, 5, 42, 43, 47, 48, 5, 42, 43, 47, + 48, 5, 42, 43, 47, 48, 5, 10, 47, 48, + 5, 11, 47, 48, 5, 5, 5, 4, 3, 5, + 7, 5, 45, 5, 46, 5, 44, 5, 5, 42, + 43, 5, 5, 42, 43, 5, 42, 43, 5, 42, + 43, 5, 42, 43, 5, 42, 43, 5, 42, 43, + 5, 42, 43, 5, 42, 43, 5, 33, 42, 43, + 5, 42, 43, 5, 42, 43, 5, 42, 43, 5, + 42, 43, 5, 42, 43, 5, 42, 43, 5, 42, + + 43, 5, 42, 43, 5, 42, 43, 5, 42, 43, + 5, 5, 5, 7, 7, 5, 46, 5, 43, 5, + 5, 42, 43, 5, 42, 43, 5, 42, 43, 5, + 42, 43, 5, 42, 43, 5, 42, 43, 5, 42, + 43, 5, 42, 43, 5, 42, 43, 5, 42, 43, + 5, 42, 43, 5, 42, 43, 5, 42, 43, 5, + 42, 43, 5, 34, 42, 43, 5, 42, 43, 5, + 42, 43, 5, 42, 43, 5, 42, 43, 5, 5, + 5, 43, 5, 42, 43, 5, 42, 43, 5, 42, + 43, 5, 42, 43, 5, 21, 42, 43, 5, 42, + + 43, 5, 29, 42, 43, 5, 42, 43, 5, 42, + 43, 5, 22, 42, 43, 5, 42, 43, 5, 42, + 43, 5, 42, 43, 5, 42, 43, 5, 42, 43, + 5, 42, 43, 5, 42, 43, 5, 42, 43, 5, + 42, 43, 5, 20, 42, 43, 5, 5, 5, 39, + 42, 43, 5, 42, 43, 5, 35, 42, 43, 5, + 42, 43, 5, 42, 43, 5, 36, 42, 43, 5, + 42, 43, 5, 42, 43, 5, 38, 42, 43, 5, + 42, 43, 5, 42, 43, 5, 42, 43, 5, 42, + 43, 5, 42, 43, 5, 42, 43, 5, 42, 43, + + 5, 5, 5, 42, 43, 5, 42, 43, 5, 42, + 43, 5, 42, 43, 5, 28, 42, 43, 5, 25, + 42, 43, 5, 40, 42, 43, 5, 42, 43, 5, + 42, 43, 5, 37, 42, 43, 5, 24, 42, 43, + 5, 26, 42, 43, 5, 5, 5, 42, 43, 5, + 23, 42, 43, 5, 41, 42, 43, 5, 42, 43, + 5, 42, 43, 5, 42, 43, 5, 5, 5, 42, + 43, 5, 42, 43, 5, 32, 42, 43, 5, 31, + 42, 43, 5, 5, 5, 30, 42, 43, 5, 27, + 42, 43, 5, 5, 5, 9, 5, 5, 9, 9, + + 5, 5, 8, 5, 8, 8 + } ; + +static yyconst short int yy_accept[177] = + { 0, + 1, 2, 3, 4, 7, 11, 13, 16, 20, 24, + 27, 31, 34, 38, 42, 46, 50, 54, 58, 62, + 67, 72, 77, 82, 87, 92, 97, 102, 107, 112, + 117, 122, 127, 131, 135, 136, 137, 138, 139, 140, + 142, 144, 146, 148, 149, 152, 153, 156, 159, 162, + 165, 168, 171, 174, 177, 181, 184, 187, 190, 193, + 196, 199, 202, 205, 208, 211, 212, 213, 215, 216, + 218, 220, 221, 224, 227, 230, 233, 236, 239, 242, + 245, 248, 251, 254, 257, 260, 263, 267, 270, 273, + 276, 279, 280, 281, 283, 286, 289, 292, 295, 299, + + 302, 306, 309, 312, 316, 319, 322, 325, 328, 331, + 334, 337, 340, 343, 347, 348, 349, 353, 356, 360, + 363, 366, 370, 373, 376, 380, 383, 386, 389, 392, + 395, 398, 401, 402, 403, 406, 409, 412, 415, 419, + 423, 427, 430, 433, 437, 441, 445, 446, 447, 450, + 454, 458, 461, 464, 467, 468, 469, 472, 475, 479, + 483, 484, 485, 489, 493, 494, 495, 497, 498, 500, + 501, 502, 504, 506, 507, 507 + } ; + +static yyconst int yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 1, 4, 1, 1, 1, 1, 5, + 6, 7, 1, 8, 1, 1, 9, 10, 11, 11, + 11, 11, 11, 11, 11, 12, 12, 13, 14, 15, + 16, 17, 1, 1, 18, 18, 18, 18, 18, 18, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 20, 19, 19, + 1, 1, 1, 1, 19, 1, 21, 22, 23, 24, + + 25, 26, 27, 19, 28, 29, 19, 30, 31, 32, + 33, 19, 34, 35, 36, 37, 38, 39, 40, 41, + 42, 19, 43, 1, 44, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst int yy_meta[45] = + { 0, + 1, 1, 2, 1, 1, 1, 3, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1 + } ; + +static yyconst short int yy_base[185] = + { 0, + 0, 0, 302, 0, 0, 669, 20, 0, 0, 289, + 0, 39, 39, 41, 279, 0, 0, 0, 0, 80, + 124, 24, 33, 36, 62, 69, 75, 81, 112, 39, + 66, 109, 0, 0, 0, 259, 222, 669, 669, 239, + 44, 159, 110, 185, 115, 232, 121, 118, 206, 198, + 128, 211, 136, 217, 202, 220, 227, 230, 233, 236, + 239, 257, 245, 249, 252, 217, 212, 225, 0, 0, + 295, 339, 281, 285, 278, 294, 321, 313, 329, 340, + 337, 299, 291, 332, 354, 348, 357, 363, 360, 377, + 380, 164, 153, 166, 383, 394, 374, 398, 388, 391, + + 401, 404, 408, 411, 420, 423, 429, 432, 438, 447, + 441, 450, 457, 453, 146, 139, 460, 470, 463, 481, + 473, 476, 489, 495, 485, 492, 498, 505, 512, 515, + 518, 521, 152, 115, 524, 531, 528, 549, 535, 538, + 541, 552, 557, 560, 563, 566, 106, 103, 569, 572, + 575, 591, 579, 594, 93, 104, 597, 600, 603, 606, + 92, 85, 609, 612, 85, 71, 83, 63, 76, 0, + 54, 71, 60, 0, 669, 64, 62, 650, 653, 46, + 656, 659, 662, 665 + } ; + +static yyconst short int yy_def[185] = + { 0, + 175, 1, 175, 176, 176, 175, 176, 176, 176, 175, + 176, 176, 176, 176, 176, 176, 176, 176, 176, 177, + 177, 21, 21, 21, 21, 21, 21, 21, 21, 21, + 21, 21, 176, 176, 176, 176, 176, 175, 175, 178, + 176, 176, 176, 175, 21, 176, 21, 21, 21, 21, + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, + 21, 21, 21, 21, 21, 176, 176, 178, 179, 42, + 180, 180, 21, 21, 21, 21, 21, 21, 21, 21, + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, + 21, 176, 176, 72, 21, 21, 21, 21, 21, 21, + + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, + 21, 21, 21, 21, 176, 176, 21, 21, 21, 21, + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, + 21, 21, 176, 176, 21, 21, 21, 21, 21, 21, + 21, 21, 21, 21, 21, 21, 176, 176, 21, 21, + 21, 21, 21, 21, 176, 176, 21, 21, 21, 21, + 176, 176, 21, 21, 176, 176, 181, 176, 181, 182, + 176, 183, 183, 184, 0, 175, 175, 175, 175, 175, + 175, 175, 175, 175 + } ; + +static yyconst short int yy_nxt[714] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 14, 15, 16, 17, 18, 19, 20, 20, 20, + 21, 22, 20, 23, 24, 25, 20, 26, 20, 27, + 28, 20, 29, 20, 30, 31, 20, 20, 32, 20, + 20, 20, 33, 34, 36, 39, 94, 40, 41, 41, + 43, 43, 43, 41, 41, 37, 50, 52, 42, 45, + 45, 45, 45, 62, 35, 51, 174, 53, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 174, 172, 42, + 35, 35, 170, 35, 35, 35, 171, 35, 35, 170, + 63, 54, 46, 35, 35, 35, 35, 45, 45, 45, + + 55, 45, 64, 45, 45, 45, 45, 56, 168, 167, + 45, 45, 45, 57, 166, 165, 45, 45, 58, 43, + 43, 43, 35, 35, 35, 35, 162, 35, 35, 35, + 161, 35, 35, 59, 156, 155, 46, 35, 35, 35, + 35, 65, 148, 60, 45, 45, 45, 45, 45, 61, + 45, 45, 45, 45, 74, 45, 45, 45, 45, 47, + 48, 49, 73, 45, 77, 45, 35, 35, 70, 70, + 70, 45, 45, 79, 147, 134, 70, 133, 46, 70, + 70, 70, 70, 70, 70, 35, 35, 116, 35, 35, + 35, 115, 35, 35, 35, 35, 35, 35, 35, 35, + + 35, 35, 71, 71, 71, 71, 71, 71, 71, 71, + 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, + 71, 71, 71, 71, 71, 71, 71, 35, 35, 75, + 76, 69, 93, 45, 45, 45, 78, 45, 81, 45, + 92, 45, 45, 45, 72, 69, 45, 45, 45, 80, + 83, 82, 45, 45, 45, 45, 45, 45, 67, 84, + 86, 85, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 87, 45, 88, 89, 91, + 45, 45, 45, 90, 45, 45, 45, 45, 45, 45, + 66, 44, 45, 45, 45, 35, 35, 38, 35, 35, + + 35, 175, 35, 35, 175, 97, 175, 46, 35, 35, + 35, 35, 95, 45, 45, 45, 45, 45, 45, 96, + 45, 45, 45, 98, 175, 104, 45, 45, 105, 45, + 45, 45, 175, 100, 45, 45, 45, 35, 35, 35, + 35, 175, 35, 35, 35, 99, 35, 35, 45, 45, + 45, 35, 35, 35, 35, 35, 45, 45, 45, 101, + 102, 103, 175, 175, 45, 45, 45, 45, 106, 45, + 175, 175, 45, 45, 45, 45, 45, 45, 107, 175, + 175, 35, 35, 45, 45, 45, 109, 108, 175, 45, + 45, 45, 45, 45, 45, 45, 45, 110, 45, 45, + + 45, 111, 175, 114, 112, 117, 119, 175, 175, 45, + 45, 45, 45, 45, 113, 45, 45, 45, 45, 45, + 45, 118, 120, 45, 45, 45, 45, 45, 121, 45, + 45, 45, 175, 45, 45, 45, 45, 45, 45, 45, + 122, 45, 123, 45, 45, 45, 45, 45, 45, 124, + 125, 126, 127, 175, 175, 45, 45, 45, 45, 45, + 45, 130, 175, 175, 45, 45, 45, 45, 45, 45, + 128, 129, 175, 45, 45, 45, 45, 45, 45, 132, + 175, 131, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 135, 45, 45, 45, 45, 45, 45, 45, 45, + + 45, 136, 137, 175, 175, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 138, 175, 45, 45, 45, 139, + 45, 45, 45, 175, 45, 45, 45, 45, 140, 45, + 45, 45, 45, 45, 45, 45, 142, 175, 175, 141, + 45, 45, 45, 143, 145, 144, 175, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 146, 45, 45, + 45, 149, 150, 45, 151, 45, 45, 45, 45, 152, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 154, + 175, 153, 175, 175, 45, 45, 45, 45, 45, 45, + 175, 175, 45, 45, 45, 45, 45, 45, 45, 45, + + 45, 45, 45, 45, 45, 157, 45, 45, 45, 45, + 45, 45, 45, 158, 45, 45, 45, 175, 160, 175, + 159, 163, 175, 175, 164, 175, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 68, 175, 68, 69, 175, 69, 169, 175, 169, 170, + 175, 170, 173, 175, 173, 174, 175, 174, 3, 175, + 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, + 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, + 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, + + 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, + 175, 175, 175 + } ; + +static yyconst short int yy_chk[714] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 7, 12, 180, 12, 13, 13, + 14, 14, 14, 41, 41, 7, 22, 23, 13, 22, + 22, 22, 177, 30, 176, 22, 173, 24, 23, 23, + 23, 24, 24, 24, 30, 30, 30, 172, 171, 13, + 20, 20, 169, 20, 20, 20, 168, 20, 20, 167, + 31, 25, 20, 20, 20, 20, 20, 25, 25, 25, + + 26, 31, 31, 31, 26, 26, 26, 27, 166, 165, + 27, 27, 27, 28, 162, 161, 28, 28, 28, 43, + 43, 43, 20, 20, 21, 21, 156, 21, 21, 21, + 155, 21, 21, 29, 148, 147, 21, 21, 21, 21, + 21, 32, 134, 29, 32, 32, 32, 29, 29, 29, + 45, 45, 45, 48, 48, 48, 47, 47, 47, 21, + 21, 21, 47, 51, 51, 51, 21, 21, 42, 42, + 42, 53, 53, 53, 133, 116, 42, 115, 94, 42, + 42, 42, 42, 42, 42, 44, 44, 93, 44, 44, + 44, 92, 44, 44, 44, 44, 44, 44, 44, 44, + + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 49, + 50, 68, 67, 50, 50, 50, 52, 55, 55, 55, + 66, 49, 49, 49, 46, 40, 52, 52, 52, 54, + 57, 56, 54, 54, 54, 56, 56, 56, 37, 58, + 60, 59, 57, 57, 57, 58, 58, 58, 59, 59, + 59, 60, 60, 60, 61, 61, 61, 62, 63, 65, + 63, 63, 63, 64, 64, 64, 64, 65, 65, 65, + 36, 15, 62, 62, 62, 71, 71, 10, 71, 71, + + 71, 3, 71, 71, 0, 75, 0, 71, 71, 71, + 71, 71, 73, 75, 75, 75, 73, 73, 73, 74, + 74, 74, 74, 76, 0, 82, 83, 83, 83, 76, + 76, 76, 0, 78, 82, 82, 82, 71, 71, 72, + 72, 0, 72, 72, 72, 77, 72, 72, 78, 78, + 78, 72, 72, 72, 72, 72, 77, 77, 77, 79, + 80, 81, 0, 0, 79, 79, 79, 84, 84, 84, + 0, 0, 81, 81, 81, 80, 80, 80, 85, 0, + 0, 72, 72, 86, 86, 86, 88, 86, 0, 85, + 85, 85, 87, 87, 87, 89, 89, 89, 88, 88, + + 88, 90, 0, 91, 90, 95, 97, 0, 0, 97, + 97, 97, 90, 90, 90, 91, 91, 91, 95, 95, + 95, 96, 98, 99, 99, 99, 100, 100, 100, 96, + 96, 96, 0, 98, 98, 98, 101, 101, 101, 102, + 102, 102, 103, 103, 103, 103, 104, 104, 104, 105, + 106, 107, 108, 0, 0, 105, 105, 105, 106, 106, + 106, 111, 0, 0, 107, 107, 107, 108, 108, 108, + 109, 110, 0, 109, 109, 109, 111, 111, 111, 113, + 0, 112, 110, 110, 110, 112, 112, 112, 114, 114, + 114, 118, 113, 113, 113, 117, 117, 117, 119, 119, + + 119, 120, 121, 0, 0, 118, 118, 118, 121, 121, + 121, 122, 122, 122, 123, 0, 120, 120, 120, 124, + 125, 125, 125, 0, 123, 123, 123, 126, 126, 126, + 124, 124, 124, 127, 127, 127, 128, 0, 0, 127, + 128, 128, 128, 129, 131, 130, 0, 129, 129, 129, + 130, 130, 130, 131, 131, 131, 132, 132, 132, 135, + 135, 135, 136, 137, 137, 137, 136, 136, 136, 138, + 139, 139, 139, 140, 140, 140, 141, 141, 141, 143, + 0, 142, 0, 0, 138, 138, 138, 142, 142, 142, + 0, 0, 143, 143, 143, 144, 144, 144, 145, 145, + + 145, 146, 146, 146, 149, 149, 149, 150, 150, 150, + 151, 151, 151, 152, 153, 153, 153, 0, 154, 0, + 153, 157, 0, 0, 158, 0, 152, 152, 152, 154, + 154, 154, 157, 157, 157, 158, 158, 158, 159, 159, + 159, 160, 160, 160, 163, 163, 163, 164, 164, 164, + 178, 0, 178, 179, 0, 179, 181, 0, 181, 182, + 0, 182, 183, 0, 183, 184, 0, 184, 175, 175, + 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, + 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, + 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, + + 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, + 175, 175, 175 + } ; + +static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr; +static char *yy_full_match; +static int yy_lp; +#define REJECT \ +{ \ +*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \ +yy_cp = yy_full_match; /* restore poss. backed-over text */ \ +++yy_lp; \ +goto find_rule; \ +} +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "scanner.ll" +#define INITIAL 0 +/* +Copyright (C) 1999 Stefan Westerfeld +stefan@space.twc.de +Copyright (C) 1999 Torben Weis <weis@kde.org> +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 2 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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#line 25 "scanner.ll" + +/* + This is the lex file for mcopidl. It is based on the dcopidl (kidl) + lex file, which was written by Torben Weis. +*/ + +#define YY_NO_UNPUT +#define YY_NEVER_INTERACTIVE 1 + +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include "common.h" + +using namespace std; +using namespace Arts; + +#ifndef KDE_USE_FINAL +#include "yacc.cc.h" +#endif + +extern int idl_line_no; +int comment_mode; + +static long ascii_to_longlong( long base, const char *s ) +{ + long ll = 0; + while( *s != '\0' ) { + char c = *s++; + if( c >= 'a' ) + c -= 'a' - 'A'; + c -= '0'; + if( c > 9 ) + c -= 'A' - '0' - 10; + ll = ll * base + c; + } + return ll; +} + +extern void startInclude(const char *line); +extern void endInclude(); + +/*--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------*/ +#line 710 "scanner.cc" + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap YY_PROTO(( void )); +#else +extern int yywrap YY_PROTO(( void )); +#endif +#endif + +#ifndef YY_NO_UNPUT +static void yyunput YY_PROTO(( int c, char *buf_ptr )); +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen YY_PROTO(( yyconst char * )); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif +#endif + +#if YY_STACK_USED +static int yy_start_stack_ptr = 0; +static int yy_start_stack_depth = 0; +static int *yy_start_stack = 0; +#ifndef YY_NO_PUSH_STATE +static void yy_push_state YY_PROTO(( int new_state )); +#endif +#ifndef YY_NO_POP_STATE +static void yy_pop_state YY_PROTO(( void )); +#endif +#ifndef YY_NO_TOP_STATE +static int yy_top_state YY_PROTO(( void )); +#endif + +#else +#define YY_NO_PUSH_STATE 1 +#define YY_NO_POP_STATE 1 +#define YY_NO_TOP_STATE 1 +#endif + +#ifdef YY_MALLOC_DECL +YY_MALLOC_DECL +#else +#if __STDC__ +#ifndef __cplusplus +#include <stdlib.h> +#endif +#else +/* Just try to get by without declaring the routines. This will fail + * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) + * or sizeof(void*) != sizeof(int). + */ +#endif +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ + +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( yy_current_buffer->yy_is_interactive ) \ + { \ + int c = '*', n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ + && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL int yylex YY_PROTO(( void )) +#endif + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +YY_DECL + { + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 100 "scanner.ll" + + +#line 864 "scanner.cc" + + if ( yy_init ) + { + yy_init = 0; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! yy_current_buffer ) + yy_current_buffer = + yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; + yy_state_ptr = yy_state_buf; + *yy_state_ptr++ = yy_current_state; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 176 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *yy_state_ptr++ = yy_current_state; + ++yy_cp; + } + while ( yy_current_state != 175 ); + +yy_find_action: + yy_current_state = *--yy_state_ptr; + yy_lp = yy_accept[yy_current_state]; +find_rule: /* we branch to this label when backing up */ + for ( ; ; ) /* until we find what rule we matched */ + { + if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] ) + { + yy_act = yy_acclist[yy_lp]; + { + yy_full_match = yy_cp; + break; + } + } + --yy_cp; + yy_current_state = *--yy_state_ptr; + yy_lp = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + + +do_action: /* This label is used only to access EOF actions. */ + + + switch ( yy_act ) + { /* beginning of action switch */ +case 1: +YY_RULE_SETUP +#line 102 "scanner.ll" +; + YY_BREAK +case 2: +YY_RULE_SETUP +#line 103 "scanner.ll" +{ idl_line_no++; } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 105 "scanner.ll" +{ comment_mode = 1; } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 106 "scanner.ll" +{ if (!comment_mode) { REJECT; } else { comment_mode = 0; } } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 107 "scanner.ll" +{ if (!comment_mode) { REJECT; } } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 108 "scanner.ll" +{ if (!comment_mode) { REJECT; } } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 110 "scanner.ll" +; + YY_BREAK +case 8: +YY_RULE_SETUP +#line 112 "scanner.ll" +{ startInclude(yytext); } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 113 "scanner.ll" +{ endInclude(); } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 116 "scanner.ll" +return T_LEFT_CURLY_BRACKET; + YY_BREAK +case 11: +YY_RULE_SETUP +#line 117 "scanner.ll" +return T_RIGHT_CURLY_BRACKET; + YY_BREAK +case 12: +YY_RULE_SETUP +#line 118 "scanner.ll" +return T_LEFT_PARANTHESIS; + YY_BREAK +case 13: +YY_RULE_SETUP +#line 119 "scanner.ll" +return T_RIGHT_PARANTHESIS; + YY_BREAK +case 14: +YY_RULE_SETUP +#line 120 "scanner.ll" +return T_LESS; + YY_BREAK +case 15: +YY_RULE_SETUP +#line 121 "scanner.ll" +return T_GREATER; + YY_BREAK +case 16: +YY_RULE_SETUP +#line 122 "scanner.ll" +return T_COMMA; + YY_BREAK +case 17: +YY_RULE_SETUP +#line 123 "scanner.ll" +return T_SEMICOLON; + YY_BREAK +case 18: +YY_RULE_SETUP +#line 124 "scanner.ll" +return T_COLON; + YY_BREAK +case 19: +YY_RULE_SETUP +#line 125 "scanner.ll" +return T_EQUAL; + YY_BREAK +case 20: +YY_RULE_SETUP +#line 127 "scanner.ll" +return T_VOID; + YY_BREAK +case 21: +YY_RULE_SETUP +#line 128 "scanner.ll" +return T_BYTE; + YY_BREAK +case 22: +YY_RULE_SETUP +#line 129 "scanner.ll" +return T_LONG; + YY_BREAK +case 23: +YY_RULE_SETUP +#line 130 "scanner.ll" +return T_BOOLEAN; + YY_BREAK +case 24: +YY_RULE_SETUP +#line 131 "scanner.ll" +return T_STRING; + YY_BREAK +case 25: +YY_RULE_SETUP +#line 132 "scanner.ll" +return T_OBJECT; + YY_BREAK +case 26: +YY_RULE_SETUP +#line 133 "scanner.ll" +return T_STRUCT; + YY_BREAK +case 27: +YY_RULE_SETUP +#line 134 "scanner.ll" +return T_INTERFACE; + YY_BREAK +case 28: +YY_RULE_SETUP +#line 135 "scanner.ll" +return T_MODULE; + YY_BREAK +case 29: +YY_RULE_SETUP +#line 136 "scanner.ll" +return T_ENUM; + YY_BREAK +case 30: +YY_RULE_SETUP +#line 137 "scanner.ll" +return T_ATTRIBUTE; + YY_BREAK +case 31: +YY_RULE_SETUP +#line 138 "scanner.ll" +return T_SEQUENCE; + YY_BREAK +case 32: +YY_RULE_SETUP +#line 139 "scanner.ll" +return T_READONLY; + YY_BREAK +case 33: +YY_RULE_SETUP +#line 140 "scanner.ll" +return T_IN; + YY_BREAK +case 34: +YY_RULE_SETUP +#line 141 "scanner.ll" +return T_OUT; + YY_BREAK +case 35: +YY_RULE_SETUP +#line 142 "scanner.ll" +return T_AUDIO; + YY_BREAK +case 36: +YY_RULE_SETUP +#line 143 "scanner.ll" +return T_FLOAT; + YY_BREAK +case 37: +YY_RULE_SETUP +#line 144 "scanner.ll" +return T_STREAM; + YY_BREAK +case 38: +YY_RULE_SETUP +#line 145 "scanner.ll" +return T_MULTI; + YY_BREAK +case 39: +YY_RULE_SETUP +#line 146 "scanner.ll" +return T_ASYNC; + YY_BREAK +case 40: +YY_RULE_SETUP +#line 147 "scanner.ll" +return T_ONEWAY; + YY_BREAK +case 41: +YY_RULE_SETUP +#line 148 "scanner.ll" +return T_DEFAULT; + YY_BREAK +case 42: +YY_RULE_SETUP +#line 150 "scanner.ll" +{ + yylval._str = strdup(yytext); // TAKE CARE: free that thing + return T_IDENTIFIER; + } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 155 "scanner.ll" +{ + yylval._str = strdup(yytext); // TAKE CARE: free that thing + return T_QUALIFIED_IDENTIFIER; + } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 160 "scanner.ll" +{ + yylval._int = ascii_to_longlong( 10, yytext ); + return T_INTEGER_LITERAL; + } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 164 "scanner.ll" +{ + yylval._int = ascii_to_longlong( 8, yytext ); + return T_INTEGER_LITERAL; + } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 168 "scanner.ll" +{ + yylval._int = ascii_to_longlong( 16, yytext + 2 ); + return T_INTEGER_LITERAL; + } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 173 "scanner.ll" +{ + return T_UNKNOWN; + } + YY_BREAK +case 48: +YY_RULE_SETUP +#line 177 "scanner.ll" +ECHO; + YY_BREAK +#line 1205 "scanner.cc" + case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between yy_current_buffer and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yy_n_chars = yy_current_buffer->yy_n_chars; + yy_current_buffer->yy_input_file = yyin; + yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext_ptr + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_c_buf_p; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = + yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of yylex */ + + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + { + register char *dest = yy_current_buffer->yy_ch_buf; + register char *source = yytext_ptr; + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( yy_current_buffer->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_current_buffer->yy_n_chars = yy_n_chars = 0; + + else + { + int num_to_read = + yy_current_buffer->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ +#ifdef YY_USES_REJECT + YY_FATAL_ERROR( +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); +#else + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = yy_current_buffer; + + int yy_c_buf_p_offset = + (int) (yy_c_buf_p - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yy_flex_realloc( (void *) b->yy_ch_buf, + b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = yy_current_buffer->yy_buf_size - + number_to_move - 1; +#endif + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; + + return ret_val; + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +static yy_state_type yy_get_previous_state() + { + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = yy_start; + yy_state_ptr = yy_state_buf; + *yy_state_ptr++ = yy_current_state; + + for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 176 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *yy_state_ptr++ = yy_current_state; + } + + return yy_current_state; + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +yy_state_type yy_current_state; +#endif + { + register int yy_is_jam; + + register YY_CHAR yy_c = 1; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 176 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 175); + if ( ! yy_is_jam ) + *yy_state_ptr++ = yy_current_state; + + return yy_is_jam ? 0 : yy_current_state; + } + + +#ifndef YY_NO_UNPUT +#ifdef YY_USE_PROTOS +static void yyunput( int c, register char *yy_bp ) +#else +static void yyunput( c, yy_bp ) +int c; +register char *yy_bp; +#endif + { + register char *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = yy_n_chars + 2; + register char *dest = &yy_current_buffer->yy_ch_buf[ + yy_current_buffer->yy_buf_size + 2]; + register char *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + yy_current_buffer->yy_n_chars = + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + + yytext_ptr = yy_bp; + yy_hold_char = *yy_cp; + yy_c_buf_p = yy_cp; + } +#endif /* ifndef YY_NO_UNPUT */ + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + { + int c; + + *yy_c_buf_p = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* This was really a NUL. */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = yy_c_buf_p - yytext_ptr; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /* fall through */ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + return EOF; + + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ + *yy_c_buf_p = '\0'; /* preserve yytext */ + yy_hold_char = *++yy_c_buf_p; + + + return c; + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + { + if ( ! yy_current_buffer ) + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* Flush out information for old buffer. */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + { + if ( ! b ) + return; + + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yy_flex_free( (void *) b->yy_ch_buf ); + + yy_flex_free( (void *) b ); + } + + +#ifndef YY_ALWAYS_INTERACTIVE +#ifndef YY_NEVER_INTERACTIVE +extern int isatty YY_PROTO(( int )); +#endif +#endif + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + + { + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + +#if YY_ALWAYS_INTERACTIVE + b->yy_is_interactive = 1; +#else +#if YY_NEVER_INTERACTIVE + b->yy_is_interactive = 0; +#else + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; +#endif +#endif + } + + +#ifdef YY_USE_PROTOS +void yy_flush_buffer( YY_BUFFER_STATE b ) +#else +void yy_flush_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == yy_current_buffer ) + yy_load_buffer_state(); + } + + +#ifndef YY_NO_SCAN_BUFFER +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) +#else +YY_BUFFER_STATE yy_scan_buffer( base, size ) +char *base; +yy_size_t size; +#endif + { + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; + } +#endif + + +#ifndef YY_NO_SCAN_STRING +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) +#else +YY_BUFFER_STATE yy_scan_string( yy_str ) +yyconst char *yy_str; +#endif + { + int len; + for ( len = 0; yy_str[len]; ++len ) + ; + + return yy_scan_bytes( yy_str, len ); + } +#endif + + +#ifndef YY_NO_SCAN_BYTES +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) +#else +YY_BUFFER_STATE yy_scan_bytes( bytes, len ) +yyconst char *bytes; +int len; +#endif + { + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = len + 2; + buf = (char *) yy_flex_alloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < len; ++i ) + buf[i] = bytes[i]; + + buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; + } +#endif + + +#ifndef YY_NO_PUSH_STATE +#ifdef YY_USE_PROTOS +static void yy_push_state( int new_state ) +#else +static void yy_push_state( new_state ) +int new_state; +#endif + { + if ( yy_start_stack_ptr >= yy_start_stack_depth ) + { + yy_size_t new_size; + + yy_start_stack_depth += YY_START_STACK_INCR; + new_size = yy_start_stack_depth * sizeof( int ); + + if ( ! yy_start_stack ) + yy_start_stack = (int *) yy_flex_alloc( new_size ); + + else + yy_start_stack = (int *) yy_flex_realloc( + (void *) yy_start_stack, new_size ); + + if ( ! yy_start_stack ) + YY_FATAL_ERROR( + "out of memory expanding start-condition stack" ); + } + + yy_start_stack[yy_start_stack_ptr++] = YY_START; + + BEGIN(new_state); + } +#endif + + +#ifndef YY_NO_POP_STATE +static void yy_pop_state() + { + if ( --yy_start_stack_ptr < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN(yy_start_stack[yy_start_stack_ptr]); + } +#endif + + +#ifndef YY_NO_TOP_STATE +static int yy_top_state() + { + return yy_start_stack[yy_start_stack_ptr - 1]; + } +#endif + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +#ifdef YY_USE_PROTOS +static void yy_fatal_error( yyconst char msg[] ) +#else +static void yy_fatal_error( msg ) +char msg[]; +#endif + { + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); + } + + + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + yytext[yyleng] = yy_hold_char; \ + yy_c_buf_p = yytext + n; \ + yy_hold_char = *yy_c_buf_p; \ + *yy_c_buf_p = '\0'; \ + yyleng = n; \ + } \ + while ( 0 ) + + +/* Internal utility routines. */ + +#ifndef yytext_ptr +#ifdef YY_USE_PROTOS +static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) +#else +static void yy_flex_strncpy( s1, s2, n ) +char *s1; +yyconst char *s2; +int n; +#endif + { + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; + } +#endif + +#ifdef YY_NEED_STRLEN +#ifdef YY_USE_PROTOS +static int yy_flex_strlen( yyconst char *s ) +#else +static int yy_flex_strlen( s ) +yyconst char *s; +#endif + { + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; + } +#endif + + +#ifdef YY_USE_PROTOS +static void *yy_flex_alloc( yy_size_t size ) +#else +static void *yy_flex_alloc( size ) +yy_size_t size; +#endif + { + return (void *) malloc( size ); + } + +#ifdef YY_USE_PROTOS +static void *yy_flex_realloc( void *ptr, yy_size_t size ) +#else +static void *yy_flex_realloc( ptr, size ) +void *ptr; +yy_size_t size; +#endif + { + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); + } + +#ifdef YY_USE_PROTOS +static void yy_flex_free( void *ptr ) +#else +static void yy_flex_free( ptr ) +void *ptr; +#endif + { + free( ptr ); + } + +#if YY_MAIN +int main() + { + yylex(); + return 0; + } +#endif +#line 177 "scanner.ll" + + +void mcopidlInitFlex( const char *_code ) +{ + comment_mode = 0; + yy_switch_to_buffer( yy_scan_string( _code ) ); +} diff --git a/mcopidl/scanner.ll b/mcopidl/scanner.ll new file mode 100644 index 0000000..10896d2 --- /dev/null +++ b/mcopidl/scanner.ll @@ -0,0 +1,183 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + Copyright (C) 1999 Torben Weis <weis@kde.org> + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + + */ + +%{ + +/* + This is the lex file for mcopidl. It is based on the dcopidl (kidl) + lex file, which was written by Torben Weis. +*/ + +#define YY_NO_UNPUT +#define YY_NEVER_INTERACTIVE 1 + +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include "common.h" + +using namespace std; +using namespace Arts; + +#ifndef KDE_USE_FINAL +#include "yacc.cc.h" +#endif + +extern int idl_line_no; +int comment_mode; + +static long ascii_to_longlong( long base, const char *s ) +{ + long ll = 0; + while( *s != '\0' ) { + char c = *s++; + if( c >= 'a' ) + c -= 'a' - 'A'; + c -= '0'; + if( c > 9 ) + c -= 'A' - '0' - 10; + ll = ll * base + c; + } + return ll; +} + +extern void startInclude(const char *line); +extern void endInclude(); + +%} + +%option noyywrap + +/*--------------------------------------------------------------------------*/ + +Digits [0-9]+ +Oct_Digit [0-7] +Hex_Digit [a-fA-F0-9] +Int_Literal [1-9][0-9]* +Oct_Literal 0{Oct_Digit}* +Hex_Literal (0x|0X){Hex_Digit}* +Esc_Sequence1 "\\"[ntvbrfa\\\?\'\"] +Esc_Sequence2 "\\"{Oct_Digit}{1,3} +Esc_Sequence3 "\\"(x|X){Hex_Digit}{1,2} +Esc_Sequence ({Esc_Sequence1}|{Esc_Sequence2}|{Esc_Sequence3}) +Char ([^\n\t\"\'\\]|{Esc_Sequence}) +Char_Literal "'"({Char}|\")"'" +String_Literal \"({Char}|"'")*\" +Float_Literal1 {Digits}"."{Digits}(e|E)("+"|"-")?{Digits} +Float_Literal2 {Digits}(e|E)("+"|"-")?{Digits} +Float_Literal3 {Digits}"."{Digits} +Float_Literal4 "."{Digits} +Float_Literal5 "."{Digits}(e|E)("+"|"-")?{Digits} + +/*--------------------------------------------------------------------------*/ + +Kidl_Identifier [_a-zA-Z][a-zA-Z0-9_]* + +Qualified_Identifier ("::")?[_a-zA-Z](("::")?[a-zA-Z0-9_])* + +/*--------------------------------------------------------------------------*/ + +%% + +[ \t] ; +[\n] { idl_line_no++; } + +"/\*" { comment_mode = 1; } +"\*/" { if (!comment_mode) { REJECT; } else { comment_mode = 0; } } +[^\n*]* { if (!comment_mode) { REJECT; } } +"*" { if (!comment_mode) { REJECT; } } + +"//"[^\n]* ; + +"#startinclude"[^\n]* { startInclude(yytext); } +"#endinclude"[^\n]* { endInclude(); } + + +"{" return T_LEFT_CURLY_BRACKET; +"}" return T_RIGHT_CURLY_BRACKET; +"(" return T_LEFT_PARANTHESIS; +")" return T_RIGHT_PARANTHESIS; +"<" return T_LESS; +">" return T_GREATER; +"," return T_COMMA; +";" return T_SEMICOLON; +":" return T_COLON; +"=" return T_EQUAL; + +void return T_VOID; +byte return T_BYTE; +long return T_LONG; +boolean return T_BOOLEAN; +string return T_STRING; +object return T_OBJECT; +struct return T_STRUCT; +interface return T_INTERFACE; +module return T_MODULE; +"enum" return T_ENUM; +attribute return T_ATTRIBUTE; +sequence return T_SEQUENCE; +readonly return T_READONLY; +in return T_IN; +out return T_OUT; +audio return T_AUDIO; +float return T_FLOAT; +stream return T_STREAM; +multi return T_MULTI; +async return T_ASYNC; +oneway return T_ONEWAY; +default return T_DEFAULT; + +{Kidl_Identifier} { + yylval._str = strdup(yytext); // TAKE CARE: free that thing + return T_IDENTIFIER; + } + +{Qualified_Identifier} { + yylval._str = strdup(yytext); // TAKE CARE: free that thing + return T_QUALIFIED_IDENTIFIER; + } + +{Int_Literal} { + yylval._int = ascii_to_longlong( 10, yytext ); + return T_INTEGER_LITERAL; + } +{Oct_Literal} { + yylval._int = ascii_to_longlong( 8, yytext ); + return T_INTEGER_LITERAL; + } +{Hex_Literal} { + yylval._int = ascii_to_longlong( 16, yytext + 2 ); + return T_INTEGER_LITERAL; + } + +. { + return T_UNKNOWN; + } + +%% + +void mcopidlInitFlex( const char *_code ) +{ + comment_mode = 0; + yy_switch_to_buffer( yy_scan_string( _code ) ); +} diff --git a/mcopidl/yacc.cc b/mcopidl/yacc.cc new file mode 100644 index 0000000..2d6fac7 --- /dev/null +++ b/mcopidl/yacc.cc @@ -0,0 +1,1507 @@ + +/* A Bison parser, made from yacc.yy + by GNU Bison version 1.28 */ + +#define YYBISON 1 /* Identify Bison output. */ + +#define T_STRUCT 257 +#define T_ENUM 258 +#define T_INTERFACE 259 +#define T_MODULE 260 +#define T_VOID 261 +#define T_LEFT_CURLY_BRACKET 262 +#define T_RIGHT_CURLY_BRACKET 263 +#define T_LEFT_PARANTHESIS 264 +#define T_RIGHT_PARANTHESIS 265 +#define T_LESS 266 +#define T_GREATER 267 +#define T_EQUAL 268 +#define T_SEMICOLON 269 +#define T_COLON 270 +#define T_COMMA 271 +#define T_IDENTIFIER 272 +#define T_QUALIFIED_IDENTIFIER 273 +#define T_INTEGER_LITERAL 274 +#define T_UNKNOWN 275 +#define T_BOOLEAN 276 +#define T_STRING 277 +#define T_LONG 278 +#define T_BYTE 279 +#define T_OBJECT 280 +#define T_SEQUENCE 281 +#define T_AUDIO 282 +#define T_FLOAT 283 +#define T_IN 284 +#define T_OUT 285 +#define T_STREAM 286 +#define T_MULTI 287 +#define T_ATTRIBUTE 288 +#define T_READONLY 289 +#define T_ASYNC 290 +#define T_ONEWAY 291 +#define T_DEFAULT 292 + +#line 22 "yacc.yy" + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <string> +#include "common.h" +#include "namespace.h" + +using namespace std; +using namespace Arts; + +extern int idl_line_no; +extern string idl_filename; + +extern int yylex(); +extern void mcopidlInitFlex( const char *_code ); +extern void addEnumTodo( const EnumDef& edef ); +extern void addStructTodo( const TypeDef& type ); +extern void addInterfaceTodo( const InterfaceDef& iface ); + +void yyerror( const char *s ) +{ + printf( "%s:%i: %s\n", idl_filename.c_str(), idl_line_no, s ); + exit(1); + // theParser->parse_error( idl_lexFile, s, idl_line_no ); +} + +static struct ParserGlobals { + vector<string> noHints; +} *g; + + +#line 55 "yacc.yy" +typedef union +{ + // generic data types + long _int; + char* _str; + unsigned short _char; + double _float; + + vector<char*> *_strs; + + // types + vector<TypeComponent> *_typeComponentSeq; + TypeComponent* _typeComponent; + + // enums + vector<EnumComponent> *_enumComponentSeq; + + // interfaces + InterfaceDef *_interfaceDef; + + ParamDef* _paramDef; + vector<ParamDef> *_paramDefSeq; + + MethodDef* _methodDef; + vector<MethodDef> *_methodDefSeq; + + AttributeDef* _attributeDef; + vector<AttributeDef> *_attributeDefSeq; +} YYSTYPE; +#ifndef YYDEBUG +#define YYDEBUG 1 +#endif + +#include <stdio.h> + +#ifndef __cplusplus +#ifndef __STDC__ +#define const +#endif +#endif + + + +#define YYFINAL 133 +#define YYFLAG -32768 +#define YYNTBASE 39 + +#define YYTRANSLATE(x) ((unsigned)(x) <= 292 ? yytranslate[x] : 75) + +static const char yytranslate[] = { 0, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 1, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, + 37, 38 +}; + +#if YYDEBUG != 0 +static const short yyprhs[] = { 0, + 0, 2, 4, 7, 9, 11, 13, 15, 16, 21, + 22, 30, 31, 39, 41, 43, 45, 49, 53, 59, + 60, 65, 66, 75, 77, 80, 81, 82, 91, 93, + 96, 99, 102, 104, 110, 112, 114, 116, 118, 120, + 122, 129, 133, 135, 138, 140, 143, 146, 150, 153, + 157, 165, 167, 170, 172, 176, 179, 181, 185, 187, + 191, 193, 195, 197, 202, 204, 209, 211, 213, 215, + 217, 219, 221, 223, 225, 227, 229 +}; + +static const short yyrhs[] = { 40, + 0, 74, 0, 41, 40, 0, 42, 0, 49, 0, + 53, 0, 45, 0, 0, 3, 18, 43, 15, 0, + 0, 3, 18, 44, 8, 71, 9, 15, 0, 0, + 4, 47, 46, 8, 48, 9, 15, 0, 18, 0, + 74, 0, 18, 0, 18, 14, 20, 0, 48, 17, + 18, 0, 48, 17, 18, 14, 20, 0, 0, 5, + 18, 50, 15, 0, 0, 5, 18, 51, 52, 8, + 56, 9, 15, 0, 74, 0, 16, 69, 0, 0, + 0, 6, 18, 54, 8, 40, 9, 55, 15, 0, + 74, 0, 64, 56, 0, 57, 56, 0, 62, 56, + 0, 61, 0, 58, 34, 72, 68, 15, 0, 74, + 0, 35, 0, 74, 0, 37, 0, 74, 0, 38, + 0, 60, 63, 72, 32, 68, 15, 0, 38, 68, + 15, 0, 30, 0, 30, 33, 0, 31, 0, 31, + 33, 0, 36, 30, 0, 36, 30, 33, 0, 36, + 31, 0, 36, 31, 33, 0, 59, 72, 18, 10, + 65, 11, 15, 0, 74, 0, 67, 66, 0, 74, + 0, 66, 17, 67, 0, 72, 18, 0, 18, 0, + 68, 17, 18, 0, 70, 0, 69, 17, 70, 0, + 18, 0, 19, 0, 74, 0, 72, 68, 15, 71, + 0, 73, 0, 27, 12, 73, 13, 0, 22, 0, + 23, 0, 24, 0, 25, 0, 26, 0, 28, 0, + 29, 0, 7, 0, 18, 0, 19, 0, 0 +}; + +#endif + +#if YYDEBUG != 0 +static const short yyrline[] = { 0, + 124, 126, 126, 128, 128, 128, 128, 130, 132, 132, + 134, 145, 148, 160, 160, 162, 169, 175, 183, 190, + 192, 192, 193, 214, 216, 218, 221, 224, 226, 230, + 236, 247, 254, 256, 270, 272, 275, 277, 280, 282, + 285, 298, 303, 305, 306, 307, 308, 309, 310, 311, + 315, 325, 330, 338, 343, 353, 368, 370, 372, 374, + 376, 380, 386, 390, 409, 410, 423, 425, 426, 427, + 428, 429, 430, 431, 432, 436, 442 +}; +#endif + + +#if YYDEBUG != 0 || defined (YYERROR_VERBOSE) + +static const char * const yytname[] = { "$","error","$undefined.","T_STRUCT", +"T_ENUM","T_INTERFACE","T_MODULE","T_VOID","T_LEFT_CURLY_BRACKET","T_RIGHT_CURLY_BRACKET", +"T_LEFT_PARANTHESIS","T_RIGHT_PARANTHESIS","T_LESS","T_GREATER","T_EQUAL","T_SEMICOLON", +"T_COLON","T_COMMA","T_IDENTIFIER","T_QUALIFIED_IDENTIFIER","T_INTEGER_LITERAL", +"T_UNKNOWN","T_BOOLEAN","T_STRING","T_LONG","T_BYTE","T_OBJECT","T_SEQUENCE", +"T_AUDIO","T_FLOAT","T_IN","T_OUT","T_STREAM","T_MULTI","T_ATTRIBUTE","T_READONLY", +"T_ASYNC","T_ONEWAY","T_DEFAULT","aidlfile","definitions","definition","structdef", +"@1","@2","enumdef","@3","enumname","enumbody","interfacedef","@4","@5","inheritedinterfaces", +"moduledef","@6","@7","classbody","attributedef","maybereadonly","maybeoneway", +"maybedefault","streamdef","defaultdef","direction","methoddef","paramdefs", +"paramdefs1","paramdef","identifierlist","interfacelist","interfacelistelem", +"structbody","type","simpletype","epsilon", NULL +}; +#endif + +static const short yyr1[] = { 0, + 39, 40, 40, 41, 41, 41, 41, 43, 42, 44, + 42, 46, 45, 47, 47, 48, 48, 48, 48, 50, + 49, 51, 49, 52, 52, 54, 55, 53, 56, 56, + 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, + 61, 62, 63, 63, 63, 63, 63, 63, 63, 63, + 64, 65, 65, 66, 66, 67, 68, 68, 69, 69, + 70, 70, 71, 71, 72, 72, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 73, 74 +}; + +static const short yyr2[] = { 0, + 1, 1, 2, 1, 1, 1, 1, 0, 4, 0, + 7, 0, 7, 1, 1, 1, 3, 3, 5, 0, + 4, 0, 8, 1, 2, 0, 0, 8, 1, 2, + 2, 2, 1, 5, 1, 1, 1, 1, 1, 1, + 6, 3, 1, 2, 1, 2, 2, 3, 2, 3, + 7, 1, 2, 1, 3, 2, 1, 3, 1, 3, + 1, 1, 1, 4, 1, 4, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 0 +}; + +static const short yydefact[] = { 77, + 0, 77, 0, 0, 1, 77, 4, 7, 5, 6, + 2, 8, 14, 12, 15, 22, 26, 3, 0, 0, + 0, 0, 77, 0, 9, 77, 0, 21, 0, 0, + 24, 77, 74, 75, 76, 67, 68, 69, 70, 71, + 0, 72, 73, 0, 0, 65, 63, 16, 0, 61, + 62, 25, 59, 77, 0, 0, 0, 57, 0, 0, + 0, 0, 0, 36, 38, 40, 0, 77, 0, 0, + 0, 33, 77, 77, 37, 27, 0, 11, 77, 0, + 17, 13, 18, 60, 0, 0, 31, 0, 0, 43, + 45, 0, 0, 32, 30, 0, 66, 64, 58, 0, + 42, 23, 0, 0, 44, 46, 47, 49, 0, 28, + 19, 0, 77, 48, 50, 0, 34, 0, 77, 0, + 52, 0, 0, 53, 54, 56, 41, 51, 0, 55, + 0, 0, 0 +}; + +static const short yydefgoto[] = { 131, + 5, 6, 7, 19, 20, 8, 21, 14, 49, 9, + 22, 23, 30, 10, 24, 96, 67, 68, 69, 70, + 71, 72, 73, 93, 74, 118, 124, 119, 59, 52, + 53, 44, 45, 46, 75 +}; + +static const short yypact[] = { 44, + -13, 13, 16, 20,-32768, 44,-32768,-32768,-32768,-32768, +-32768, 5,-32768,-32768,-32768, 27,-32768,-32768, 30, 10, + 43, 54, 56, 65,-32768, 39, 64,-32768, 3, 75, +-32768, 44,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, + 72,-32768,-32768, 76, 68,-32768,-32768, 73, -5,-32768, +-32768, 71,-32768, -10, 80, 52, 77,-32768, -8, 70, + 78, 79, 3,-32768,-32768, 68, 82, -10, 60, 39, + -16,-32768, -10, -10, -1,-32768, 83,-32768, 39, 81, +-32768,-32768, 84,-32768, 22, 85,-32768, 39, 86, 62, + 69, 25, 39,-32768,-32768, 88,-32768,-32768,-32768, 87, +-32768,-32768, 68, 91,-32768,-32768, 89, 90, 74,-32768, +-32768, 26, 39,-32768,-32768, 68,-32768, 94,-32768, 92, +-32768, 37, 93, 95,-32768,-32768,-32768,-32768, 39,-32768, + 109, 111,-32768 +}; + +static const short yypgoto[] = {-32768, + 4,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, +-32768,-32768,-32768,-32768,-32768,-32768, -57,-32768,-32768,-32768, +-32768,-32768,-32768,-32768,-32768,-32768,-32768, -15, -63,-32768, + 53, 36, -69, 61, 0 +}; + + +#define YYLAST 123 + + +static const short yytable[] = { 11, + 89, 15, 85, 61, 12, 11, 79, -29, 80, 18, + 87, 62, -10, 90, 91, 94, 95, 26, 103, 92, + 50, 51, 31, 109, 64, 47, 65, 66, -39, -39, + 13, 11, -35, 16, -39, 55, 101, 17, 80, 112, + 117, -20, 80, 120, 25, 33, 1, 2, 3, 4, + 27, 127, 122, 80, 107, 108, 34, 35, 33, 120, + 36, 37, 38, 39, 40, 41, 42, 43, 28, 34, + 35, 29, 32, 36, 37, 38, 39, 40, 47, 42, + 43, 48, 54, 56, 57, 58, 60, 63, 76, 81, + 86, 78, 82, 88, 105, 97, 83, 100, 99, 102, + 113, 106, 110, 104, 123, 116, 111, 128, 132, 126, + 133, 129, 121, 130, 98, 84, 77, 0, 125, 0, + 0, 114, 115 +}; + +static const short yycheck[] = { 0, + 70, 2, 66, 9, 18, 6, 15, 9, 17, 6, + 68, 17, 8, 30, 31, 73, 74, 8, 88, 36, + 18, 19, 23, 93, 35, 26, 37, 38, 30, 31, + 18, 32, 34, 18, 36, 32, 15, 18, 17, 103, + 15, 15, 17, 113, 15, 7, 3, 4, 5, 6, + 8, 15, 116, 17, 30, 31, 18, 19, 7, 129, + 22, 23, 24, 25, 26, 27, 28, 29, 15, 18, + 19, 16, 8, 22, 23, 24, 25, 26, 79, 28, + 29, 18, 8, 12, 9, 18, 14, 17, 9, 20, + 9, 15, 15, 34, 33, 13, 18, 14, 18, 15, + 10, 33, 15, 18, 11, 32, 20, 15, 0, 18, + 0, 17, 113, 129, 79, 63, 56, -1, 119, -1, + -1, 33, 33 +}; +/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ +#line 3 "/usr/share/misc/bison.simple" +/* This file comes from bison-1.28. */ + +/* Skeleton output parser for bison, + Copyright (C) 1984, 1989, 1990 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 2, 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, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* This is the parser code that is written into each bison parser + when the %semantic_parser declaration is not specified in the grammar. + It was written by Richard Stallman by simplifying the hairy parser + used when %semantic_parser is specified. */ + +#ifndef YYSTACK_USE_ALLOCA +#ifdef alloca +#define YYSTACK_USE_ALLOCA +#else /* alloca not defined */ +#ifdef __GNUC__ +#define YYSTACK_USE_ALLOCA +#define alloca __builtin_alloca +#else /* not GNU C. */ +#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386)) +#define YYSTACK_USE_ALLOCA +#include <alloca.h> +#else /* not sparc */ +/* We think this test detects Watcom and Microsoft C. */ +/* This used to test MSDOS, but that is a bad idea + since that symbol is in the user namespace. */ +#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__) +#if 0 /* No need for malloc.h, which pollutes the namespace; + instead, just don't use alloca. */ +#include <malloc.h> +#endif +#else /* not MSDOS, or __TURBOC__ */ +#if defined(_AIX) +/* I don't know what this was needed for, but it pollutes the namespace. + So I turned it off. rms, 2 May 1997. */ +/* #include <malloc.h> */ + #pragma alloca +#define YYSTACK_USE_ALLOCA +#else /* not MSDOS, or __TURBOC__, or _AIX */ +#if 0 +#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up, + and on HPUX 10. Eventually we can turn this on. */ +#define YYSTACK_USE_ALLOCA +#define alloca __builtin_alloca +#endif /* __hpux */ +#endif +#endif /* not _AIX */ +#endif /* not MSDOS, or __TURBOC__ */ +#endif /* not sparc */ +#endif /* not GNU C */ +#endif /* alloca not defined */ +#endif /* YYSTACK_USE_ALLOCA not defined */ + +#ifdef YYSTACK_USE_ALLOCA +#define YYSTACK_ALLOC alloca +#else +#define YYSTACK_ALLOC malloc +#endif + +/* Note: there must be only one dollar sign in this file. + It is replaced by the list of actions, each action + as one case of the switch. */ + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY -2 +#define YYEOF 0 +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrlab1 +/* Like YYERROR except do call yyerror. + This remains here temporarily to ease the + transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ +#define YYFAIL goto yyerrlab +#define YYRECOVERING() (!!yyerrstatus) +#define YYBACKUP(token, value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { yychar = (token), yylval = (value); \ + yychar1 = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { yyerror ("syntax error: cannot back up"); YYERROR; } \ +while (0) + +#define YYTERROR 1 +#define YYERRCODE 256 + +#ifndef YYPURE +#define YYLEX yylex() +#endif + +#ifdef YYPURE +#ifdef YYLSP_NEEDED +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval, &yylloc) +#endif +#else /* not YYLSP_NEEDED */ +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval) +#endif +#endif /* not YYLSP_NEEDED */ +#endif + +/* If nonreentrant, generate the variables here */ + +#ifndef YYPURE + +int yychar; /* the lookahead symbol */ +YYSTYPE yylval; /* the semantic value of the */ + /* lookahead symbol */ + +#ifdef YYLSP_NEEDED +YYLTYPE yylloc; /* location data for the lookahead */ + /* symbol */ +#endif + +int yynerrs; /* number of parse errors so far */ +#endif /* not YYPURE */ + +#if YYDEBUG != 0 +int yydebug; /* nonzero means print parse trace */ +/* Since this is uninitialized, it does not stop multiple parsers + from coexisting. */ +#endif + +/* YYINITDEPTH indicates the initial size of the parser's stacks */ + +#ifndef YYINITDEPTH +#define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH is the maximum size the stacks can grow to + (effective only if the built-in stack extension method is used). */ + +#if YYMAXDEPTH == 0 +#undef YYMAXDEPTH +#endif + +#ifndef YYMAXDEPTH +#define YYMAXDEPTH 10000 +#endif + +/* Define __yy_memcpy. Note that the size argument + should be passed with type unsigned int, because that is what the non-GCC + definitions require. With GCC, __builtin_memcpy takes an arg + of type size_t, but it can handle unsigned int. */ + +#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ +#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT) +#else /* not GNU C or C++ */ +#ifndef __cplusplus + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (to, from, count) + char *to; + char *from; + unsigned int count; +{ + register char *f = from; + register char *t = to; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#else /* __cplusplus */ + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (char *to, char *from, unsigned int count) +{ + register char *t = to; + register char *f = from; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#endif +#endif + +#line 217 "/usr/share/misc/bison.simple" + +/* The user can define YYPARSE_PARAM as the name of an argument to be passed + into yyparse. The argument should have type void *. + It should actually point to an object. + Grammar actions can access the variable by casting it + to the proper pointer type. */ + +#ifdef YYPARSE_PARAM +#ifdef __cplusplus +#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM +#define YYPARSE_PARAM_DECL +#else /* not __cplusplus */ +#define YYPARSE_PARAM_ARG YYPARSE_PARAM +#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; +#endif /* not __cplusplus */ +#else /* not YYPARSE_PARAM */ +#define YYPARSE_PARAM_ARG +#define YYPARSE_PARAM_DECL +#endif /* not YYPARSE_PARAM */ + +/* Prevent warning if -Wstrict-prototypes. */ +#ifdef __GNUC__ +#ifdef YYPARSE_PARAM +int yyparse (void *); +#else +int yyparse (void); +#endif +#endif + +int +yyparse(YYPARSE_PARAM_ARG) + YYPARSE_PARAM_DECL +{ + register int yystate; + register int yyn; + register short *yyssp; + register YYSTYPE *yyvsp; + int yyerrstatus; /* number of tokens to shift before error messages enabled */ + int yychar1 = 0; /* lookahead token as an internal (translated) token number */ + + short yyssa[YYINITDEPTH]; /* the state stack */ + YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */ + + short *yyss = yyssa; /* refer to the stacks thru separate pointers */ + YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ + +#ifdef YYLSP_NEEDED + YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp; + +#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) +#else +#define YYPOPSTACK (yyvsp--, yyssp--) +#endif + + int yystacksize = YYINITDEPTH; + int yyfree_stacks = 0; + +#ifdef YYPURE + int yychar; + YYSTYPE yylval; + int yynerrs; +#ifdef YYLSP_NEEDED + YYLTYPE yylloc; +#endif +#endif + + YYSTYPE yyval; /* the variable used to return */ + /* semantic values from the action */ + /* routines */ + + int yylen; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Starting parse\n"); +#endif + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss - 1; + yyvsp = yyvs; +#ifdef YYLSP_NEEDED + yylsp = yyls; +#endif + +/* Push a new state, which is found in yystate . */ +/* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. */ +yynewstate: + + *++yyssp = yystate; + + if (yyssp >= yyss + yystacksize - 1) + { + /* Give user a chance to reallocate the stack */ + /* Use copies of these so that the &'s don't force the real ones into memory. */ + YYSTYPE *yyvs1 = yyvs; + short *yyss1 = yyss; +#ifdef YYLSP_NEEDED + YYLTYPE *yyls1 = yyls; +#endif + + /* Get the current used size of the three stacks, in elements. */ + int size = yyssp - yyss + 1; + +#ifdef yyoverflow + /* Each stack pointer address is followed by the size of + the data in use in that stack, in bytes. */ +#ifdef YYLSP_NEEDED + /* This used to be a conditional around just the two extra args, + but that might be undefined if yyoverflow is a macro. */ + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yyls1, size * sizeof (*yylsp), + &yystacksize); +#else + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yystacksize); +#endif + + yyss = yyss1; yyvs = yyvs1; +#ifdef YYLSP_NEEDED + yyls = yyls1; +#endif +#else /* no yyoverflow */ + /* Extend the stack our own way. */ + if (yystacksize >= YYMAXDEPTH) + { + yyerror("parser stack overflow"); + if (yyfree_stacks) + { + free (yyss); + free (yyvs); +#ifdef YYLSP_NEEDED + free (yyls); +#endif + } + return 2; + } + yystacksize *= 2; + if (yystacksize > YYMAXDEPTH) + yystacksize = YYMAXDEPTH; +#ifndef YYSTACK_USE_ALLOCA + yyfree_stacks = 1; +#endif + yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); + __yy_memcpy ((char *)yyss, (char *)yyss1, + size * (unsigned int) sizeof (*yyssp)); + yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp)); + __yy_memcpy ((char *)yyvs, (char *)yyvs1, + size * (unsigned int) sizeof (*yyvsp)); +#ifdef YYLSP_NEEDED + yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp)); + __yy_memcpy ((char *)yyls, (char *)yyls1, + size * (unsigned int) sizeof (*yylsp)); +#endif +#endif /* no yyoverflow */ + + yyssp = yyss + size - 1; + yyvsp = yyvs + size - 1; +#ifdef YYLSP_NEEDED + yylsp = yyls + size - 1; +#endif + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Stack size increased to %d\n", yystacksize); +#endif + + if (yyssp >= yyss + yystacksize - 1) + YYABORT; + } + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Entering state %d\n", yystate); +#endif + + goto yybackup; + yybackup: + +/* Do appropriate processing given the current state. */ +/* Read a lookahead token if we need one and don't already have one. */ +/* yyresume: */ + + /* First try to decide what to do without reference to lookahead token. */ + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* yychar is either YYEMPTY or YYEOF + or a valid token in external form. */ + + if (yychar == YYEMPTY) + { +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Reading a token: "); +#endif + yychar = YYLEX; + } + + /* Convert token to internal form (in yychar1) for indexing tables with */ + + if (yychar <= 0) /* This means end of input. */ + { + yychar1 = 0; + yychar = YYEOF; /* Don't call YYLEX any more */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Now at end of input.\n"); +#endif + } + else + { + yychar1 = YYTRANSLATE(yychar); + +#if YYDEBUG != 0 + if (yydebug) + { + fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); + /* Give the individual parser a way to print the precise meaning + of a token, for further debugging info. */ +#ifdef YYPRINT + YYPRINT (stderr, yychar, yylval); +#endif + fprintf (stderr, ")\n"); + } +#endif + } + + yyn += yychar1; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) + goto yydefault; + + yyn = yytable[yyn]; + + /* yyn is what to do for this token type in this state. + Negative => reduce, -yyn is rule number. + Positive => shift, yyn is new state. + New state is final state => don't bother to shift, + just return success. + 0, or most negative number => error. */ + + if (yyn < 0) + { + if (yyn == YYFLAG) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrlab; + + if (yyn == YYFINAL) + YYACCEPT; + + /* Shift the lookahead token. */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); +#endif + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + /* count tokens shifted since error; after three, turn off error status. */ + if (yyerrstatus) yyerrstatus--; + + yystate = yyn; + goto yynewstate; + +/* Do the default action for the current state. */ +yydefault: + + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + +/* Do a reduction. yyn is the number of a rule to reduce with. */ +yyreduce: + yylen = yyr2[yyn]; + if (yylen > 0) + yyval = yyvsp[1-yylen]; /* implement default value of the action */ + +#if YYDEBUG != 0 + if (yydebug) + { + int i; + + fprintf (stderr, "Reducing via rule %d (line %d), ", + yyn, yyrline[yyn]); + + /* Print the symbols being reduced, and their result. */ + for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) + fprintf (stderr, "%s ", yytname[yyrhs[i]]); + fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); + } +#endif + + + switch (yyn) { + +case 8: +#line 131 "yacc.yy" +{ ModuleHelper::define(yyvsp[0]._str); ; + break;} +case 10: +#line 132 "yacc.yy" +{ ModuleHelper::define(yyvsp[0]._str); ; + break;} +case 11: +#line 137 "yacc.yy" +{ + char *qualified = ModuleHelper::qualify(yyvsp[-5]._str); + addStructTodo(TypeDef(qualified,*yyvsp[-2]._typeComponentSeq,g->noHints)); + free(qualified); + free(yyvsp[-5]._str); + ; + break;} +case 12: +#line 146 "yacc.yy" +{ ModuleHelper::define(yyvsp[0]._str); ; + break;} +case 13: +#line 151 "yacc.yy" +{ + char *qualified = ModuleHelper::qualify(yyvsp[-5]._str); + addEnumTodo(EnumDef(qualified,*yyvsp[-2]._enumComponentSeq,g->noHints)); + free(qualified); + free(yyvsp[-5]._str); + delete yyvsp[-2]._enumComponentSeq; + ; + break;} +case 14: +#line 160 "yacc.yy" +{ yyval._str = yyvsp[0]._str; ; + break;} +case 15: +#line 160 "yacc.yy" +{ yyval._str = strdup("_anonymous_"); ; + break;} +case 16: +#line 164 "yacc.yy" +{ + yyval._enumComponentSeq = new vector<EnumComponent>; + yyval._enumComponentSeq->push_back(EnumComponent(yyvsp[0]._str,0,g->noHints)); + free(yyvsp[0]._str); + ; + break;} +case 17: +#line 170 "yacc.yy" +{ + yyval._enumComponentSeq = new vector<EnumComponent>; + yyval._enumComponentSeq->push_back(EnumComponent(yyvsp[-2]._str,yyvsp[0]._int,g->noHints)); + free(yyvsp[-2]._str); + ; + break;} +case 18: +#line 176 "yacc.yy" +{ + EnumComponent& last = (*yyvsp[-2]._enumComponentSeq)[yyvsp[-2]._enumComponentSeq->size()-1]; + + yyval._enumComponentSeq = yyvsp[-2]._enumComponentSeq; + yyval._enumComponentSeq->push_back(EnumComponent(yyvsp[0]._str,last.value+1,g->noHints)); + free(yyvsp[0]._str); + ; + break;} +case 19: +#line 184 "yacc.yy" +{ + yyval._enumComponentSeq = yyvsp[-4]._enumComponentSeq; + yyval._enumComponentSeq->push_back(EnumComponent(yyvsp[-2]._str,yyvsp[0]._int,g->noHints)); + free(yyvsp[-2]._str); + ; + break;} +case 20: +#line 191 "yacc.yy" +{ ModuleHelper::define(yyvsp[0]._str); ; + break;} +case 22: +#line 192 "yacc.yy" +{ ModuleHelper::define(yyvsp[0]._str); ; + break;} +case 23: +#line 197 "yacc.yy" +{ + vector<char *>::iterator ii; + for(ii=yyvsp[-4]._strs->begin(); ii != yyvsp[-4]._strs->end(); ii++) + { + yyvsp[-2]._interfaceDef->inheritedInterfaces.push_back(*ii); + free(*ii); + } + delete yyvsp[-4]._strs; + char *qualified = ModuleHelper::qualify(yyvsp[-6]._str); + yyvsp[-2]._interfaceDef->name = qualified; + free(qualified); + free(yyvsp[-6]._str); + addInterfaceTodo(*yyvsp[-2]._interfaceDef); + delete yyvsp[-2]._interfaceDef; + ; + break;} +case 24: +#line 215 "yacc.yy" +{ yyval._strs = new vector<char *>; ; + break;} +case 25: +#line 216 "yacc.yy" +{ yyval._strs = yyvsp[0]._strs; ; + break;} +case 26: +#line 219 "yacc.yy" +{ ModuleHelper::enter(yyvsp[0]._str); free(yyvsp[0]._str); ; + break;} +case 27: +#line 222 "yacc.yy" +{ ModuleHelper::leave(); ; + break;} +case 29: +#line 227 "yacc.yy" +{ + yyval._interfaceDef = new InterfaceDef(); + ; + break;} +case 30: +#line 231 "yacc.yy" +{ + yyval._interfaceDef = yyvsp[0]._interfaceDef; + yyval._interfaceDef->methods.insert(yyval._interfaceDef->methods.begin(),*yyvsp[-1]._methodDef); + delete yyvsp[-1]._methodDef; + ; + break;} +case 31: +#line 237 "yacc.yy" +{ + yyval._interfaceDef = yyvsp[0]._interfaceDef; + yyval._interfaceDef->attributes.insert(yyval._interfaceDef->attributes.begin(),yyvsp[-1]._attributeDefSeq->begin(),yyvsp[-1]._attributeDefSeq->end()); + if ((*yyvsp[-1]._attributeDefSeq)[0].flags & streamDefault) { + vector<std::string> sv; + for (vector<AttributeDef>::iterator i=yyvsp[-1]._attributeDefSeq->begin(); i!=yyvsp[-1]._attributeDefSeq->end(); i++) + sv.push_back(i->name); + yyval._interfaceDef->defaultPorts.insert(yyval._interfaceDef->defaultPorts.begin(),sv.begin(),sv.end()); + } + ; + break;} +case 32: +#line 248 "yacc.yy" +{ + yyval._interfaceDef = yyvsp[0]._interfaceDef; + for (vector<char *>::iterator i=yyvsp[-1]._strs->begin(); i!=yyvsp[-1]._strs->end(); i++) + yyval._interfaceDef->defaultPorts.insert(yyval._interfaceDef->defaultPorts.begin(), *i); + ; + break;} +case 34: +#line 257 "yacc.yy" +{ + // 16 == attribute + vector<char *>::iterator i; + yyval._attributeDefSeq = new vector<AttributeDef>; + for(i=yyvsp[-1]._strs->begin();i != yyvsp[-1]._strs->end();i++) + { + yyval._attributeDefSeq->push_back(AttributeDef((*i),yyvsp[-2]._str,(AttributeType)(yyvsp[-4]._int + 16),g->noHints)); + free(*i); + } + delete yyvsp[-1]._strs; + ; + break;} +case 35: +#line 271 "yacc.yy" +{ yyval._int = 1+2; /* in&out (read & write) */ ; + break;} +case 36: +#line 272 "yacc.yy" +{ yyval._int = 2; /* out (readonly) */ ; + break;} +case 37: +#line 276 "yacc.yy" +{ yyval._int = methodTwoway; ; + break;} +case 38: +#line 277 "yacc.yy" +{ yyval._int = methodOneway; ; + break;} +case 39: +#line 281 "yacc.yy" +{ yyval._int = 0; ; + break;} +case 40: +#line 282 "yacc.yy" +{ yyval._int = streamDefault; ; + break;} +case 41: +#line 286 "yacc.yy" +{ + // 8 == stream + vector<char *>::iterator i; + yyval._attributeDefSeq = new vector<AttributeDef>; + for(i=yyvsp[-1]._strs->begin();i != yyvsp[-1]._strs->end();i++) + { + yyval._attributeDefSeq->push_back(AttributeDef((*i),yyvsp[-3]._str,(AttributeType)((yyvsp[-4]._int|yyvsp[-5]._int) + 8),g->noHints)); + free(*i); + } + delete yyvsp[-1]._strs; + ; + break;} +case 42: +#line 299 "yacc.yy" +{ + yyval._strs = yyvsp[-1]._strs; + ; + break;} +case 43: +#line 304 "yacc.yy" +{ yyval._int = streamIn; ; + break;} +case 44: +#line 305 "yacc.yy" +{ yyval._int = streamIn|streamMulti; ; + break;} +case 45: +#line 306 "yacc.yy" +{ yyval._int = streamOut; ; + break;} +case 46: +#line 307 "yacc.yy" +{ yyval._int = streamOut|streamMulti; ; + break;} +case 47: +#line 308 "yacc.yy" +{ yyval._int = streamAsync|streamIn; ; + break;} +case 48: +#line 309 "yacc.yy" +{ yyval._int =streamAsync|streamIn|streamMulti ; + break;} +case 49: +#line 310 "yacc.yy" +{ yyval._int = streamAsync|streamOut; ; + break;} +case 50: +#line 311 "yacc.yy" +{ yyval._int = streamAsync|streamOut|streamMulti; ; + break;} +case 51: +#line 318 "yacc.yy" +{ + yyval._methodDef = new MethodDef(yyvsp[-4]._str,yyvsp[-5]._str,(MethodType)yyvsp[-6]._int,*yyvsp[-2]._paramDefSeq,g->noHints); + free(yyvsp[-4]._str); + free(yyvsp[-5]._str); + ; + break;} +case 52: +#line 327 "yacc.yy" +{ + yyval._paramDefSeq = new vector<ParamDef>; + ; + break;} +case 53: +#line 331 "yacc.yy" +{ + yyval._paramDefSeq = yyvsp[0]._paramDefSeq; + yyval._paramDefSeq->insert(yyval._paramDefSeq->begin(),*yyvsp[-1]._paramDef); + delete yyvsp[-1]._paramDef; + ; + break;} +case 54: +#line 340 "yacc.yy" +{ + yyval._paramDefSeq = new vector<ParamDef>; + ; + break;} +case 55: +#line 344 "yacc.yy" +{ + yyval._paramDefSeq = yyvsp[-2]._paramDefSeq; + yyval._paramDefSeq->push_back(*yyvsp[0]._paramDef); + delete yyvsp[0]._paramDef; + //$$->insert($$->begin(),$3); + ; + break;} +case 56: +#line 354 "yacc.yy" +{ + yyval._paramDef = new ParamDef(string(yyvsp[-1]._str),string(yyvsp[0]._str),g->noHints); + free(yyvsp[-1]._str); + free(yyvsp[0]._str); + ; + break;} +case 57: +#line 369 "yacc.yy" +{ yyval._strs = new vector<char *>; yyval._strs->push_back(yyvsp[0]._str); ; + break;} +case 58: +#line 370 "yacc.yy" +{ yyval._strs = yyvsp[-2]._strs; yyval._strs->push_back(yyvsp[0]._str); ; + break;} +case 59: +#line 373 "yacc.yy" +{ yyval._strs = new vector<char *>; yyval._strs->push_back(yyvsp[0]._str); ; + break;} +case 60: +#line 374 "yacc.yy" +{ yyval._strs = yyvsp[-2]._strs; yyval._strs->push_back(yyvsp[0]._str); ; + break;} +case 61: +#line 376 "yacc.yy" +{ + yyval._str = ModuleHelper::qualify(yyvsp[0]._str); + free(yyvsp[0]._str); + ; + break;} +case 62: +#line 380 "yacc.yy" +{ + yyval._str = ModuleHelper::qualify(yyvsp[0]._str); + free(yyvsp[0]._str); + ; + break;} +case 63: +#line 386 "yacc.yy" +{ + // is empty by default + yyval._typeComponentSeq = new vector<TypeComponent>; + ; + break;} +case 64: +#line 390 "yacc.yy" +{ + yyval._typeComponentSeq = yyvsp[0]._typeComponentSeq; + vector<char *>::reverse_iterator i; + for(i = yyvsp[-2]._strs->rbegin();i != yyvsp[-2]._strs->rend();i++) + { + char *identifier = *i; + + yyval._typeComponentSeq->insert(yyval._typeComponentSeq->begin(),TypeComponent(yyvsp[-3]._str,identifier,g->noHints)); + free(identifier); + } + delete yyvsp[-2]._strs; + ; + break;} +case 66: +#line 411 "yacc.yy" +{ + // a sequence<long> is for instance coded as *long + + // alloc new size: add one for the null byte and one for the '*' char + char *result = (char *)malloc(strlen(yyvsp[-1]._str)+2); + result[0] = '*'; + strcpy(&result[1],yyvsp[-1]._str); + free(yyvsp[-1]._str); /* fails */ + + yyval._str = result; + ; + break;} +case 67: +#line 424 "yacc.yy" +{ yyval._str = strdup("boolean"); ; + break;} +case 68: +#line 425 "yacc.yy" +{ yyval._str = strdup("string"); ; + break;} +case 69: +#line 426 "yacc.yy" +{ yyval._str = strdup("long"); ; + break;} +case 70: +#line 427 "yacc.yy" +{ yyval._str = strdup("byte"); ; + break;} +case 71: +#line 428 "yacc.yy" +{ yyval._str = strdup("object"); ; + break;} +case 72: +#line 429 "yacc.yy" +{ yyval._str = strdup("float"); ; + break;} +case 73: +#line 430 "yacc.yy" +{ yyval._str = strdup("float"); ; + break;} +case 74: +#line 431 "yacc.yy" +{ yyval._str = strdup("void"); ; + break;} +case 75: +#line 432 "yacc.yy" +{ + yyval._str = ModuleHelper::qualify(yyvsp[0]._str); + free(yyvsp[0]._str); + ; + break;} +case 76: +#line 436 "yacc.yy" +{ + yyval._str = ModuleHelper::qualify(yyvsp[0]._str); + free(yyvsp[0]._str); + ; + break;} +} + /* the action file gets copied in in place of this dollarsign */ +#line 543 "/usr/share/misc/bison.simple" + + yyvsp -= yylen; + yyssp -= yylen; +#ifdef YYLSP_NEEDED + yylsp -= yylen; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + + *++yyvsp = yyval; + +#ifdef YYLSP_NEEDED + yylsp++; + if (yylen == 0) + { + yylsp->first_line = yylloc.first_line; + yylsp->first_column = yylloc.first_column; + yylsp->last_line = (yylsp-1)->last_line; + yylsp->last_column = (yylsp-1)->last_column; + yylsp->text = 0; + } + else + { + yylsp->last_line = (yylsp+yylen-1)->last_line; + yylsp->last_column = (yylsp+yylen-1)->last_column; + } +#endif + + /* Now "shift" the result of the reduction. + Determine what state that goes to, + based on the state we popped back to + and the rule number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTBASE] + *yyssp; + if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTBASE]; + + goto yynewstate; + +yyerrlab: /* here on detecting error */ + + if (! yyerrstatus) + /* If not already recovering from an error, report this error. */ + { + ++yynerrs; + +#ifdef YYERROR_VERBOSE + yyn = yypact[yystate]; + + if (yyn > YYFLAG && yyn < YYLAST) + { + int size = 0; + char *msg; + int x, count; + + count = 0; + /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ + for (x = (yyn < 0 ? -yyn : 0); + x < (sizeof(yytname) / sizeof(char *)); x++) + if (yycheck[x + yyn] == x) + size += strlen(yytname[x]) + 15, count++; + msg = (char *) malloc(size + 15); + if (msg != 0) + { + strcpy(msg, "parse error"); + + if (count < 5) + { + count = 0; + for (x = (yyn < 0 ? -yyn : 0); + x < (sizeof(yytname) / sizeof(char *)); x++) + if (yycheck[x + yyn] == x) + { + strcat(msg, count == 0 ? ", expecting `" : " or `"); + strcat(msg, yytname[x]); + strcat(msg, "'"); + count++; + } + } + yyerror(msg); + free(msg); + } + else + yyerror ("parse error; also virtual memory exceeded"); + } + else +#endif /* YYERROR_VERBOSE */ + yyerror("parse error"); + } + + goto yyerrlab1; +yyerrlab1: /* here on error raised explicitly by an action */ + + if (yyerrstatus == 3) + { + /* if just tried and failed to reuse lookahead token after an error, discard it. */ + + /* return failure if at end of input */ + if (yychar == YYEOF) + YYABORT; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); +#endif + + yychar = YYEMPTY; + } + + /* Else will try to reuse lookahead token + after shifting the error token. */ + + yyerrstatus = 3; /* Each real token shifted decrements this */ + + goto yyerrhandle; + +yyerrdefault: /* current state does not do anything special for the error token. */ + +#if 0 + /* This is wrong; only states that explicitly want error tokens + should shift them. */ + yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ + if (yyn) goto yydefault; +#endif + +yyerrpop: /* pop the current state because it cannot handle the error token */ + + if (yyssp == yyss) YYABORT; + yyvsp--; + yystate = *--yyssp; +#ifdef YYLSP_NEEDED + yylsp--; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "Error: state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + +yyerrhandle: + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yyerrdefault; + + yyn += YYTERROR; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) + goto yyerrdefault; + + yyn = yytable[yyn]; + if (yyn < 0) + { + if (yyn == YYFLAG) + goto yyerrpop; + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrpop; + + if (yyn == YYFINAL) + YYACCEPT; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting error token, "); +#endif + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + yystate = yyn; + goto yynewstate; + + yyacceptlab: + /* YYACCEPT comes here. */ + if (yyfree_stacks) + { + free (yyss); + free (yyvs); +#ifdef YYLSP_NEEDED + free (yyls); +#endif + } + return 0; + + yyabortlab: + /* YYABORT comes here. */ + if (yyfree_stacks) + { + free (yyss); + free (yyvs); +#ifdef YYLSP_NEEDED + free (yyls); +#endif + } + return 1; +} +#line 443 "yacc.yy" + + +void mcopidlParse( const char *_code ) +{ + g = new ParserGlobals; + mcopidlInitFlex( _code ); + yyparse(); + delete g; +} diff --git a/mcopidl/yacc.cc.h b/mcopidl/yacc.cc.h new file mode 100644 index 0000000..a600e21 --- /dev/null +++ b/mcopidl/yacc.cc.h @@ -0,0 +1,75 @@ + +#ifndef YACC_CC_H +#define YACC_CC_H + +typedef union +{ + // generic data types + long _int; + char* _str; + unsigned short _char; + double _float; + + vector<char*> *_strs; + + // types + vector<TypeComponent> *_typeComponentSeq; + TypeComponent* _typeComponent; + + // enums + vector<EnumComponent> *_enumComponentSeq; + + // interfaces + InterfaceDef *_interfaceDef; + + ParamDef* _paramDef; + vector<ParamDef> *_paramDefSeq; + + MethodDef* _methodDef; + vector<MethodDef> *_methodDefSeq; + + AttributeDef* _attributeDef; + vector<AttributeDef> *_attributeDefSeq; +} YYSTYPE; +#define T_STRUCT 257 +#define T_ENUM 258 +#define T_INTERFACE 259 +#define T_MODULE 260 +#define T_VOID 261 +#define T_LEFT_CURLY_BRACKET 262 +#define T_RIGHT_CURLY_BRACKET 263 +#define T_LEFT_PARANTHESIS 264 +#define T_RIGHT_PARANTHESIS 265 +#define T_LESS 266 +#define T_GREATER 267 +#define T_EQUAL 268 +#define T_SEMICOLON 269 +#define T_COLON 270 +#define T_COMMA 271 +#define T_IDENTIFIER 272 +#define T_QUALIFIED_IDENTIFIER 273 +#define T_INTEGER_LITERAL 274 +#define T_UNKNOWN 275 +#define T_BOOLEAN 276 +#define T_STRING 277 +#define T_LONG 278 +#define T_BYTE 279 +#define T_OBJECT 280 +#define T_SEQUENCE 281 +#define T_AUDIO 282 +#define T_FLOAT 283 +#define T_IN 284 +#define T_OUT 285 +#define T_STREAM 286 +#define T_MULTI 287 +#define T_ATTRIBUTE 288 +#define T_READONLY 289 +#define T_ASYNC 290 +#define T_ONEWAY 291 +#define T_DEFAULT 292 + + +extern YYSTYPE yylval; + +#endif // YACC_CC_H + diff --git a/mcopidl/yacc.yy b/mcopidl/yacc.yy new file mode 100644 index 0000000..9e90fbe --- /dev/null +++ b/mcopidl/yacc.yy @@ -0,0 +1,451 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld, stefan@space.twc.de + Nicolas Brodu, nicolas.brodu@free.fr + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + + */ + +%{ +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <string> +#include "common.h" +#include "namespace.h" + +using namespace std; +using namespace Arts; + +extern int idl_line_no; +extern string idl_filename; + +extern int yylex(); +extern void mcopidlInitFlex( const char *_code ); +extern void addEnumTodo( const EnumDef& edef ); +extern void addStructTodo( const TypeDef& type ); +extern void addInterfaceTodo( const InterfaceDef& iface ); + +void yyerror( const char *s ) +{ + printf( "%s:%i: %s\n", idl_filename.c_str(), idl_line_no, s ); + exit(1); + // theParser->parse_error( idl_lexFile, s, idl_line_no ); +} + +static struct ParserGlobals { + vector<string> noHints; +} *g; + +%} + +%union +{ + // generic data types + long _int; + char* _str; + unsigned short _char; + double _float; + + vector<char*> *_strs; + + // types + vector<TypeComponent> *_typeComponentSeq; + TypeComponent* _typeComponent; + + // enums + vector<EnumComponent> *_enumComponentSeq; + + // interfaces + InterfaceDef *_interfaceDef; + + ParamDef* _paramDef; + vector<ParamDef> *_paramDefSeq; + + MethodDef* _methodDef; + vector<MethodDef> *_methodDefSeq; + + AttributeDef* _attributeDef; + vector<AttributeDef> *_attributeDefSeq; +} + +%token T_STRUCT T_ENUM T_INTERFACE T_MODULE T_VOID +%token T_LEFT_CURLY_BRACKET T_RIGHT_CURLY_BRACKET +%token T_LEFT_PARANTHESIS T_RIGHT_PARANTHESIS +%token T_LESS T_GREATER T_EQUAL +%token T_SEMICOLON T_COLON T_COMMA +%token<_str> T_IDENTIFIER T_QUALIFIED_IDENTIFIER +%type<_str> type +%type<_str> simpletype +%type<_str> enumname +%type<_str> interfacelistelem +/*%type<_typeComponent> typecomponentdef*/ +%type<_typeComponentSeq> structbody +%type<_paramDef> paramdef +%type<_paramDefSeq> paramdefs +%type<_paramDefSeq> paramdefs1 +%type<_methodDef> methoddef +%type<_attributeDefSeq> attributedef +%type<_attributeDefSeq> streamdef +%type<_interfaceDef> classbody +%type<_enumComponentSeq> enumbody +%type<_strs> interfacelist +%type<_strs> identifierlist +%type<_strs> defaultdef +%type<_strs> inheritedinterfaces + +%type<_int> maybereadonly +%type<_int> direction +%type<_int> maybeoneway +%type<_int> maybedefault + +%token T_INTEGER_LITERAL T_UNKNOWN +%type<_int> T_INTEGER_LITERAL + +%token T_BOOLEAN T_STRING T_LONG T_BYTE T_OBJECT T_SEQUENCE T_AUDIO T_FLOAT +%token T_IN T_OUT T_STREAM T_MULTI T_ATTRIBUTE T_READONLY T_ASYNC T_ONEWAY +%token T_DEFAULT + +%% + +aidlfile: definitions; + +definitions: epsilon | definition definitions ; + +definition: structdef | interfacedef | moduledef | enumdef ; + +structdef: + T_STRUCT T_IDENTIFIER { ModuleHelper::define($2); } T_SEMICOLON + | T_STRUCT T_IDENTIFIER { ModuleHelper::define($2); } + T_LEFT_CURLY_BRACKET + structbody + T_RIGHT_CURLY_BRACKET + T_SEMICOLON + { + char *qualified = ModuleHelper::qualify($2); + addStructTodo(TypeDef(qualified,*$5,g->noHints)); + free(qualified); + free($2); + } + ; + +enumdef: + T_ENUM enumname { ModuleHelper::define($2); } + T_LEFT_CURLY_BRACKET + enumbody + T_RIGHT_CURLY_BRACKET + T_SEMICOLON + { + char *qualified = ModuleHelper::qualify($2); + addEnumTodo(EnumDef(qualified,*$5,g->noHints)); + free(qualified); + free($2); + delete $5; + } + ; + +enumname: T_IDENTIFIER { $$ = $1; } | epsilon { $$ = strdup("_anonymous_"); }; + +enumbody: + T_IDENTIFIER + { + $$ = new vector<EnumComponent>; + $$->push_back(EnumComponent($1,0,g->noHints)); + free($1); + } + | T_IDENTIFIER T_EQUAL T_INTEGER_LITERAL + { + $$ = new vector<EnumComponent>; + $$->push_back(EnumComponent($1,$3,g->noHints)); + free($1); + } + | enumbody T_COMMA T_IDENTIFIER + { + EnumComponent& last = (*$1)[$1->size()-1]; + + $$ = $1; + $$->push_back(EnumComponent($3,last.value+1,g->noHints)); + free($3); + } + | enumbody T_COMMA T_IDENTIFIER T_EQUAL T_INTEGER_LITERAL + { + $$ = $1; + $$->push_back(EnumComponent($3,$5,g->noHints)); + free($3); + }; + +interfacedef: + T_INTERFACE T_IDENTIFIER { ModuleHelper::define($2); } T_SEMICOLON + | T_INTERFACE T_IDENTIFIER { ModuleHelper::define($2); } inheritedinterfaces + T_LEFT_CURLY_BRACKET + classbody + T_RIGHT_CURLY_BRACKET + T_SEMICOLON + { + vector<char *>::iterator ii; + for(ii=$4->begin(); ii != $4->end(); ii++) + { + $6->inheritedInterfaces.push_back(*ii); + free(*ii); + } + delete $4; + char *qualified = ModuleHelper::qualify($2); + $6->name = qualified; + free(qualified); + free($2); + addInterfaceTodo(*$6); + delete $6; + } + ; + +inheritedinterfaces: + epsilon { $$ = new vector<char *>; } + | T_COLON interfacelist { $$ = $2; }; + +moduledef: + T_MODULE T_IDENTIFIER { ModuleHelper::enter($2); free($2); } + T_LEFT_CURLY_BRACKET + definitions + T_RIGHT_CURLY_BRACKET { ModuleHelper::leave(); } + T_SEMICOLON + ; + +classbody: + epsilon { + $$ = new InterfaceDef(); + } + | methoddef classbody + { + $$ = $2; + $$->methods.insert($$->methods.begin(),*$1); + delete $1; + } + | attributedef classbody + { + $$ = $2; + $$->attributes.insert($$->attributes.begin(),$1->begin(),$1->end()); + if ((*$1)[0].flags & streamDefault) { + vector<std::string> sv; + for (vector<AttributeDef>::iterator i=$1->begin(); i!=$1->end(); i++) + sv.push_back(i->name); + $$->defaultPorts.insert($$->defaultPorts.begin(),sv.begin(),sv.end()); + } + } + | defaultdef classbody + { + $$ = $2; + for (vector<char *>::iterator i=$1->begin(); i!=$1->end(); i++) + $$->defaultPorts.insert($$->defaultPorts.begin(), *i); + }; + +attributedef: + streamdef + | maybereadonly T_ATTRIBUTE type identifierlist T_SEMICOLON + { + // 16 == attribute + vector<char *>::iterator i; + $$ = new vector<AttributeDef>; + for(i=$4->begin();i != $4->end();i++) + { + $$->push_back(AttributeDef((*i),$3,(AttributeType)($1 + 16),g->noHints)); + free(*i); + } + delete $4; + } + ; + +maybereadonly: + epsilon { $$ = 1+2; /* in&out (read & write) */ } + | T_READONLY { $$ = 2; /* out (readonly) */ } + ; + +maybeoneway: + epsilon { $$ = methodTwoway; } + | T_ONEWAY { $$ = methodOneway; } + ; + +maybedefault: + epsilon { $$ = 0; } + | T_DEFAULT { $$ = streamDefault; } + ; + +streamdef: maybedefault direction type T_STREAM identifierlist T_SEMICOLON + { + // 8 == stream + vector<char *>::iterator i; + $$ = new vector<AttributeDef>; + for(i=$5->begin();i != $5->end();i++) + { + $$->push_back(AttributeDef((*i),$3,(AttributeType)(($2|$1) + 8),g->noHints)); + free(*i); + } + delete $5; + }; + +defaultdef: T_DEFAULT identifierlist T_SEMICOLON + { + $$ = $2; + }; + +direction: + T_IN { $$ = streamIn; } + | T_IN T_MULTI { $$ = streamIn|streamMulti; } + | T_OUT { $$ = streamOut; } + | T_OUT T_MULTI { $$ = streamOut|streamMulti; } + | T_ASYNC T_IN { $$ = streamAsync|streamIn; } + | T_ASYNC T_IN T_MULTI { $$ =streamAsync|streamIn|streamMulti } + | T_ASYNC T_OUT { $$ = streamAsync|streamOut; } + | T_ASYNC T_OUT T_MULTI { $$ = streamAsync|streamOut|streamMulti; } + ; + +// CacheElement getFromCache(string name, bool hit) +methoddef: + maybeoneway type T_IDENTIFIER + T_LEFT_PARANTHESIS paramdefs T_RIGHT_PARANTHESIS T_SEMICOLON + { + $$ = new MethodDef($3,$2,(MethodType)$1,*$5,g->noHints); + free($3); + free($2); + } + ; + +paramdefs: + epsilon + { + $$ = new vector<ParamDef>; + } + | paramdef paramdefs1 + { + $$ = $2; + $$->insert($$->begin(),*$1); + delete $1; + }; + +// at least one parameter (ex: "long a" or "long a, long b, string c") +paramdefs1: + epsilon + { + $$ = new vector<ParamDef>; + } + | paramdefs1 T_COMMA paramdef + { + $$ = $1; + $$->push_back(*$3); + delete $3; + //$$->insert($$->begin(),$3); + } + ; + +// one parameter (ex: "long a") +paramdef: type T_IDENTIFIER + { + $$ = new ParamDef(string($1),string($2),g->noHints); + free($1); + free($2); + }; + +/* +typecomponentdef: type T_IDENTIFIER T_SEMICOLON + { + $$ = new TypeComponent($1,string($2)); + free($2); + }; +*/ + +identifierlist: + T_IDENTIFIER { $$ = new vector<char *>; $$->push_back($1); } + | identifierlist T_COMMA T_IDENTIFIER { $$ = $1; $$->push_back($3); } + +interfacelist: + interfacelistelem { $$ = new vector<char *>; $$->push_back($1); } + | interfacelist T_COMMA interfacelistelem { $$ = $1; $$->push_back($3); } + +interfacelistelem: T_IDENTIFIER { + $$ = ModuleHelper::qualify($1); + free($1); + } + | T_QUALIFIED_IDENTIFIER { + $$ = ModuleHelper::qualify($1); + free($1); + } + ; + +structbody: epsilon { + // is empty by default + $$ = new vector<TypeComponent>; + } + | type identifierlist T_SEMICOLON structbody { + $$ = $4; + vector<char *>::reverse_iterator i; + for(i = $2->rbegin();i != $2->rend();i++) + { + char *identifier = *i; + + $$->insert($$->begin(),TypeComponent($1,identifier,g->noHints)); + free(identifier); + } + delete $2; + }; + /* + | typecomponentdef structbody { + $$ = $2; + $$->insert($$->begin(),$1); + }; + */ + +type: simpletype + | T_SEQUENCE T_LESS simpletype T_GREATER + { + // a sequence<long> is for instance coded as *long + + // alloc new size: add one for the null byte and one for the '*' char + char *result = (char *)malloc(strlen($3)+2); + result[0] = '*'; + strcpy(&result[1],$3); + free($3); /* fails */ + + $$ = result; + }; + +simpletype: + T_BOOLEAN { $$ = strdup("boolean"); } + | T_STRING { $$ = strdup("string"); } + | T_LONG { $$ = strdup("long"); } + | T_BYTE { $$ = strdup("byte"); } + | T_OBJECT { $$ = strdup("object"); } + | T_AUDIO { $$ = strdup("float"); } + | T_FLOAT { $$ = strdup("float"); } + | T_VOID { $$ = strdup("void"); } + | T_IDENTIFIER { + $$ = ModuleHelper::qualify($1); + free($1); + } + | T_QUALIFIED_IDENTIFIER { + $$ = ModuleHelper::qualify($1); + free($1); + }; + + +epsilon: /* empty */ ; +%% + +void mcopidlParse( const char *_code ) +{ + g = new ParserGlobals; + mcopidlInitFlex( _code ); + yyparse(); + delete g; +} |