// -*- mode:C++; tab-width:2; c-basic-offset:2; indent-tabs-mode:nil -*-
//
// Copyright (C) 2000-2005 by Roger Rene Kommer / artefaktur, Kassel, Germany.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public License (LGPL).
//
//
// 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
// License ACDK-FreeLicense document enclosed in the distribution
// for more for more details.
// This file is part of the Artefaktur Component Development Kit:
// ACDK
//
// Please refer to
// - http://www.acdk.de
// - http://www.artefaktur.com
// - http://acdk.sourceforge.net
// for more information.
//
// $Header: /cvsroot/acdk/acdk/acdkx_orb/src/acdkx/orb/mc/GenOrbIdlAttribute.cpp,v 1.7 2005/02/05 10:45:40 kommer Exp $
#if 0 // dead code
#include "GenOrbIdlAttribute.h"
#include <acdk/io/FileWriter.h>
#include <acdk/lang/System.h>
namespace acdkx {
namespace orb {
namespace mc {
USING_CLASS(acdk::util::, Iterator);
using ::acdk::lang::reflect::Modifier;
/*
TODOS:
- Handling von Exceptions
- Handling von Constructors
- Typedefs other R'Classes
- Handling von Arrays mit typedef auf sequences
- Altname
*/
void
GenOrbIdlAttribute::initOut()
{
if (_out != Nil)
return;
//System::in->readLine();
RString fname = MetaCompiler::getMetaCompiler()->_baseOutname;
if (fname == Nil)
{
fname = "Unit";
}
fname = fname + "_orb.idl";
_out = new acdk::io::PrintWriter(new ::acdk::io::FileWriter(fname));
_out->println("//\n// Generated by acdkmc and acdkx/orb/mc/GenOrbIdlAttribute \n//");
}
RStringArray interfaceTypeDefs;
void addInterfaceTypeDefs(IN(RString) td)
{
for (int i = 0; i < interfaceTypeDefs->length(); ++i)
{
if (interfaceTypeDefs[i]->equals(td) == true)
return;
}
interfaceTypeDefs->append(td);
}
RString
AcdkTypeToIdl(IN(RString) type)
{
if (type->equals("RString") == true)
return "string";
if (type->equals("int") == true)
return "long";
if (type->equals("byte") == true)
return "octet";
if (type->charAt(0) == 'R')
{
if (type->endsWith("Array") == true)
{
}
else
{
addInterfaceTypeDefs(type->substr(1));
}
return type->substr(1);
}
return type;
}
void writeParam(StringBuffer& sb, IN(RClassInfo) ci, IN(RMethodInfo) mi, IN(RArgumentInfo) ai)
{
if (ai->flags == 0)
sb << "in ";
if (ai->flags & Modifier::OutParam)
{
if (ai->flags & Modifier::InParam)
sb << "inout ";
else
sb << "out ";
} else if (ai->flags & Modifier::InParam) {
sb << "in ";
}
sb << AcdkTypeToIdl(ai->type) << " " << ai->name;
}
void writeInterfaceDef(StringBuffer& sb, IN(RClassInfo) ci, IN(RMethodInfo) mi)
{
sb << " " << AcdkTypeToIdl(mi->returnType) << " ";
if (mi->_altName != Nil)
sb << mi->_altName;
else
sb << mi->name;
sb << "(";
RIterator it = mi->args->iterator();
bool firstParam = true;
while (it->hasNext() == true)
{
RArgumentInfo ai = RArgumentInfo(it->next());
if (firstParam == false)
sb << ", ";
writeParam(sb, ci, mi, ai);
firstParam = false;
}
sb << ")";
// ## exceptions
sb << ";\n";
}
void writeClass1(StringBuffer& sb, IN(RClassInfo) ci)
{
// throwable or struct
sb << "\n\ninterface " << ci->name << "\n{\n";
RIterator it = ci->_methods->iterator();
while (it->hasNext() == true)
{
writeInterfaceDef(sb, ci, RMethodInfo(it->next()));
}
sb << "};\n\n";
it = ci->_namespace->iterator();
}
void writeTypeDefs(StringBuffer& sb, IN(RClassInfo) ci)
{
for (int i = 0; i < interfaceTypeDefs->length(); ++i)
{
RString iname = interfaceTypeDefs[i];
sb << "interface " << iname << ";\n";
sb << "typedef sequence<" << iname << "> " << iname << "Array;\n";
}
}
void writeClass2(StringBuffer& sb, IN(RClassInfo) ci, IN(RString) body)
{
RIterator it = ci->_namespace->iterator();
while (it->hasNext() == true)
{
RString ns = RString(it->next());
sb << "module " << ns << "{\n";
}
writeTypeDefs(sb, ci);
sb << body;
it = ci->_namespace->iterator();
while (it->hasNext() == true)
{
RString ns = RString(it->next());
sb << "}; //module " << ns << "\n";
}
}
bool
GenOrbIdlAttribute::apply(IN(RModuleInfo) cm)
{
initOut();
RIterator it = cm->_classes->iterator();
StringBuffer sb;
while (it->hasNext() == true)
{
RClassInfo ci(it->next());
interfaceTypeDefs = new StringArray(0);
writeClass1(sb, ci);
RString body = sb.toString();
sb.reset();
writeClass2(sb, ci, body);
}
interfaceTypeDefs = Nil;
_out->print(sb.toString());
return true;
}
} // namespace mc
} // namespace orb
} // namespace acdkx
#endif //0
|