summaryrefslogtreecommitdiff
path: root/idlc
diff options
context:
space:
mode:
authorJuergen Schmidt <jsc@openoffice.org>2001-03-15 11:30:43 +0000
committerJuergen Schmidt <jsc@openoffice.org>2001-03-15 11:30:43 +0000
commitb9bb8ffb57bdc220082a292abeb6b3ea22ac2253 (patch)
tree8fdb8d2d2637dee852b829f7029d51ed1a499c4f /idlc
parentea4bd2c669909d300834aa0465365b3072b6254e (diff)
new
Diffstat (limited to 'idlc')
-rw-r--r--idlc/source/astarray.cxx107
-rw-r--r--idlc/source/astconstant.cxx184
-rw-r--r--idlc/source/astdeclaration.cxx227
-rw-r--r--idlc/source/astdump.cxx414
-rw-r--r--idlc/source/astenum.cxx161
-rw-r--r--idlc/source/astexpression.cxx1638
-rw-r--r--idlc/source/astinterface.cxx160
-rw-r--r--idlc/source/astoperation.cxx196
-rw-r--r--idlc/source/astscope.cxx385
-rw-r--r--idlc/source/aststack.cxx174
-rw-r--r--idlc/source/aststruct.cxx156
-rw-r--r--idlc/source/astunion.cxx430
-rw-r--r--idlc/source/errorhandler.cxx653
-rw-r--r--idlc/source/fehelper.cxx192
-rw-r--r--idlc/source/idlc.cxx323
-rw-r--r--idlc/source/idlccompile.cxx332
-rw-r--r--idlc/source/idlcmain.cxx135
-rw-r--r--idlc/source/idlcproduce.cxx284
-rw-r--r--idlc/source/makefile.mk147
-rw-r--r--idlc/source/options.cxx372
-rw-r--r--idlc/source/scanner.ll466
21 files changed, 7136 insertions, 0 deletions
diff --git a/idlc/source/astarray.cxx b/idlc/source/astarray.cxx
new file mode 100644
index 000000000000..d133c380eee4
--- /dev/null
+++ b/idlc/source/astarray.cxx
@@ -0,0 +1,107 @@
+/*************************************************************************
+ *
+ * $RCSfile: astarray.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTARRAY_HXX_
+#include <idlc/astarray.hxx>
+#endif
+
+using namespace ::rtl;
+
+AstArray::AstArray(const OString& name, AstType* pType, const ExprList& rDimExpr, AstScope* pScope)
+ : AstType(NT_array, name, pScope)
+ , m_pType(pType)
+ , m_dimension(rDimExpr.size())
+ , m_dimExpressions(rDimExpr)
+{
+ if ( m_pType )
+ setName(makeName());
+}
+
+AstArray::AstArray(AstType* pType, const ExprList& rDimExpr, AstScope* pScope)
+ : AstType(NT_array, OString("arrary_"), pScope)
+ , m_pType(pType)
+ , m_dimension(rDimExpr.size())
+ , m_dimExpressions(rDimExpr)
+{
+ if ( m_pType )
+ setName(makeName());
+}
+
+OString AstArray::makeName()
+{
+ if ( m_pType )
+ {
+ OString name(m_pType->getScopedName());
+ OString openBracket("[");
+ OString closeBracket("]");
+ ExprList::iterator iter = m_dimExpressions.begin();
+ ExprList::iterator end = m_dimExpressions.end();
+
+ while ( iter != end )
+ {
+ name += openBracket;
+ name += (*iter)->toString();
+ name += closeBracket;
+ iter++;
+ }
+ return name;
+ }
+ return OString();
+}
diff --git a/idlc/source/astconstant.cxx b/idlc/source/astconstant.cxx
new file mode 100644
index 000000000000..bb377a0ed3e7
--- /dev/null
+++ b/idlc/source/astconstant.cxx
@@ -0,0 +1,184 @@
+/*************************************************************************
+ *
+ * $RCSfile: astconstant.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTCONSTANT_HXX_
+#include <idlc/astconstant.hxx>
+#endif
+#ifndef _IDLC_ASTSCOPE_HXX_
+#include <idlc/astscope.hxx>
+#endif
+
+using namespace ::rtl;
+
+AstConstant::AstConstant(const ExprType type,
+ const NodeType nodeType,
+ AstExpression* pExpr,
+ const ::rtl::OString& name,
+ AstScope* pScope)
+ : AstDeclaration(nodeType, name, pScope)
+ , m_pConstValue(pExpr)
+ , m_constValueType(type)
+{
+}
+
+AstConstant::AstConstant(const ExprType type,
+ AstExpression* pExpr,
+ const ::rtl::OString& name,
+ AstScope* pScope)
+ : AstDeclaration(NT_const, name, pScope)
+ , m_pConstValue(pExpr)
+ , m_constValueType(type)
+{
+}
+
+AstConstant::~AstConstant()
+{
+
+}
+
+sal_Bool AstConstant::dumpBlob(RegistryTypeWriter& rBlob, sal_uInt16 index)
+{
+ RTConstValue aConst;
+ sal_Unicode* str = NULL;
+ sal_Bool bRelativ = sal_False;
+ if ( getScope()->getScopeNodeType() == NT_constants )
+ bRelativ = sal_True;
+
+ AstExprValue *exprVal = getConstValue()->getExprValue();
+ switch (getConstValueType())
+ {
+ case ET_short:
+ aConst.m_type = RT_TYPE_INT16;
+ aConst.m_value.aShort = exprVal->u.sval;
+ break;
+ case ET_ushort:
+ aConst.m_type = RT_TYPE_UINT16;
+ aConst.m_value.aUShort = exprVal->u.usval;
+ break;
+ case ET_long:
+ aConst.m_type = RT_TYPE_INT32;
+ aConst.m_value.aLong = exprVal->u.lval;
+ break;
+ case ET_ulong:
+ aConst.m_type = RT_TYPE_UINT32;
+ aConst.m_value.aULong = exprVal->u.ulval;
+ break;
+ case ET_hyper:
+ aConst.m_type = RT_TYPE_INT64;
+ aConst.m_value.aHyper = exprVal->u.hval;
+ break;
+ case ET_uhyper:
+ aConst.m_type = RT_TYPE_UINT64;
+ aConst.m_value.aUHyper = exprVal->u.uhval;
+ break;
+ case ET_float:
+ aConst.m_type = RT_TYPE_FLOAT;
+ aConst.m_value.aFloat = exprVal->u.fval;
+ break;
+ case ET_double:
+ aConst.m_type = RT_TYPE_DOUBLE;
+ aConst.m_value.aDouble = exprVal->u.dval;
+ break;
+ case ET_char:
+ break;
+ case ET_byte:
+ aConst.m_type = RT_TYPE_BYTE;
+ aConst.m_value.aByte = exprVal->u.byval;
+ break;
+ case ET_boolean:
+ aConst.m_type = RT_TYPE_BOOL;
+ aConst.m_value.aBool = exprVal->u.bval;
+ break;
+ case ET_string:
+ {
+ aConst.m_type = RT_TYPE_STRING;
+ ::rtl::OUString aTempStr( OUString::createFromAscii(exprVal->u.strval->getStr()));
+ str = new sal_Unicode[aTempStr.getLength()+1];
+ rtl_copyMemory(str, aTempStr.getStr(), (aTempStr.getLength()+1) * sizeof(sal_Unicode));
+ aConst.m_value.aString = str;
+ }
+ break;
+ default:
+ {
+ fprintf(stderr, "%s: exprtype to const type: cannot convert ExprType\n",
+ idlc()->getOptions()->getProgramName().getStr());
+ return sal_False;
+ }
+ }
+
+ OString name(getRelativName());
+ if ( getNodeType() == NT_enum_val || bRelativ )
+ name = getLocalName();
+
+ OUString type;
+ OUString fileName;
+ if ( getNodeType() != NT_enum_val )
+ {
+ type = OStringToOUString(exprTypeToString(getConstValueType()), RTL_TEXTENCODING_UTF8);
+ fileName = OStringToOUString(getFileName(), RTL_TEXTENCODING_UTF8);
+ }
+
+ rBlob.setFieldData(index, OStringToOUString(name, RTL_TEXTENCODING_UTF8), type,
+ getDocumentation(), fileName, RT_ACCESS_CONST, aConst);
+ if (str)
+ delete[] str;
+
+ return sal_True;
+}
diff --git a/idlc/source/astdeclaration.cxx b/idlc/source/astdeclaration.cxx
new file mode 100644
index 000000000000..70baf1b1523f
--- /dev/null
+++ b/idlc/source/astdeclaration.cxx
@@ -0,0 +1,227 @@
+/*************************************************************************
+ *
+ * $RCSfile: astdeclaration.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTDECLARATION_HXX_
+#include <idlc/astdeclaration.hxx>
+#endif
+#ifndef _IDLC_ASTSCOPE_HXX_
+#include <idlc/astscope.hxx>
+#endif
+#ifndef _RTL_STRBUF_HXX_
+#include <rtl/strbuf.hxx>
+#endif
+
+using namespace ::rtl;
+
+static OString sGlobal("::");
+
+static OString convertName(const OString& name)
+{
+ OStringBuffer nameBuffer(name.getLength()+1);
+ sal_Int32 count = name.getTokenCount(':');
+ if ( count )
+ {
+ sal_Int32 offset = (name.indexOf("::") == 0 ? 2 : 0);
+ for (sal_Int32 i=offset; i < count; i+=2 )
+ {
+ nameBuffer.append('/');
+ nameBuffer.append(name.getToken(i, ':'));
+ }
+ } else
+ {
+ nameBuffer.append('/');
+ nameBuffer.append(name);
+ }
+ return nameBuffer.makeStringAndClear();
+}
+
+AstDeclaration::AstDeclaration(NodeType type, const OString& name, AstScope* pScope)
+ : m_nodeType(type)
+ , m_localName(name)
+ , m_pScope(pScope)
+ , m_bIsAdded(sal_False)
+ , m_bImported(sal_False)
+ , m_bInMainFile(sal_False)
+{
+ if ( m_pScope )
+ {
+ AstDeclaration* pDecl = scopeAsDecl(m_pScope);
+ if (pDecl)
+ {
+ m_scopedName = pDecl->getScopedName();
+ if (m_scopedName.getLength() > 0)
+ m_scopedName += sGlobal;
+ m_scopedName += m_localName;
+ }
+ } else
+ {
+ m_scopedName = m_localName;
+ }
+ m_fullName = convertName(m_scopedName);
+
+ if ( idlc()->getFileName() == idlc()->getRealFileName() )
+ {
+ m_fileName = idlc()->getMainFileName();
+ m_bInMainFile = sal_True;
+ } else
+ {
+ m_fileName = idlc()->getFileName();
+ m_bImported = sal_True;
+ }
+
+ if ( idlc()->isDocValid() )
+ m_documentation = OStringToOUString(idlc()->getDocumentation(), RTL_TEXTENCODING_UTF8);
+}
+
+
+AstDeclaration::~AstDeclaration()
+{
+
+}
+
+void AstDeclaration::setName(const ::rtl::OString& name)
+{
+ sal_Int32 count = name.getTokenCount(':');
+ if ( count > 0 )
+ {
+ m_localName = name.getToken(count-1, ':');
+ m_scopedName = name;
+ } else if ( m_pScope )
+ {
+ m_localName = name;
+ AstDeclaration* pDecl = scopeAsDecl(m_pScope);
+ if (pDecl)
+ {
+ m_scopedName = pDecl->getScopedName();
+ if (m_scopedName.getLength() > 0)
+ m_scopedName += sGlobal;
+ m_scopedName += m_localName;
+ }
+ } else
+ {
+ m_localName = name;
+ m_scopedName = name;
+ }
+ m_fullName = convertName(m_scopedName);
+}
+
+sal_Bool AstDeclaration::isType()
+{
+ sal_Bool bIsType = sal_False;
+
+ switch (m_nodeType)
+ {
+ case NT_interface:
+ case NT_struct:
+ case NT_union:
+ case NT_enum:
+ case NT_sequence:
+ case NT_array:
+ case NT_typedef:
+ case NT_predefined:
+ bIsType = sal_True;
+ }
+
+ return bIsType;
+}
+
+sal_Bool AstDeclaration::hasAncestor(AstDeclaration* pDecl)
+{
+ if (this == pDecl)
+ return sal_True;
+ if ( !m_pScope )
+ return sal_False;
+ return scopeAsDecl(m_pScope)->hasAncestor(pDecl);
+}
+
+sal_Bool AstDeclaration::dump(RegistryKey& rKey, RegistryTypeWriterLoader* pLoader)
+{
+ AstScope* pScope = declAsScope(this);
+ sal_Bool bRet = sal_True;
+
+ if ( pScope )
+ {
+ DeclList::iterator iter = pScope->getIteratorBegin();
+ DeclList::iterator end = pScope->getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+ while ( iter != end && bRet)
+ {
+ pDecl = *iter;
+ if ( pDecl->isInMainfile() )
+ {
+ switch ( pDecl->getNodeType() )
+ {
+ case NT_module:
+ case NT_constants:
+ case NT_interface:
+ case NT_struct:
+ case NT_exception:
+ case NT_enum:
+ case NT_union:
+ case NT_typedef:
+ case NT_service:
+ bRet = pDecl->dump(rKey, pLoader);
+ }
+ }
+ iter++;
+ }
+ }
+ return bRet;
+}
diff --git a/idlc/source/astdump.cxx b/idlc/source/astdump.cxx
new file mode 100644
index 000000000000..cb5352b86427
--- /dev/null
+++ b/idlc/source/astdump.cxx
@@ -0,0 +1,414 @@
+/*************************************************************************
+ *
+ * $RCSfile: astdump.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTMODULE_HXX_
+#include <idlc/astmodule.hxx>
+#endif
+#ifndef _IDLC_ASTTYPEDEF_HXX_
+#include <idlc/asttypedef.hxx>
+#endif
+#ifndef _IDLC_ASTSERVICE_HXX_
+#include <idlc/astservice.hxx>
+#endif
+#ifndef _IDLC_ASTCONSTANT_HXX_
+#include <idlc/astconstant.hxx>
+#endif
+#ifndef _IDLC_ASTATTRIBUTE_HXX_
+#include <idlc/astattribute.hxx>
+#endif
+#ifndef _IDLC_ASTINTERFACEMEMBER_HXX_
+#include <idlc/astinterfacemember.hxx>
+#endif
+#ifndef _IDLC_ASTSERVICEEMEMBER_HXX_
+#include <idlc/astservicemember.hxx>
+#endif
+#ifndef _IDLC_ASTOBSERVES_HXX_
+#include <idlc/astobserves.hxx>
+#endif
+#ifndef _IDLC_ASTNEEDS_HXX_
+#include <idlc/astneeds.hxx>
+#endif
+#ifndef _IDLC_ASTSEQUENCE_HXX_
+#include <idlc/astsequence.hxx>
+#endif
+
+using namespace ::rtl;
+
+sal_Bool AstModule::dump(RegistryKey& rKey, RegistryTypeWriterLoader* pLoader)
+{
+ RegistryKey localKey;
+ if ( getNodeType() == NT_root )
+ {
+ localKey = rKey;
+ }else
+ {
+ if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
+ {
+ fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName().getStr(), rKey.getRegistryName().getStr());
+ return sal_False;
+ }
+ }
+
+ const sal_uInt8* pBlob = NULL;
+ sal_uInt32 aBlobSize = 0;
+ sal_uInt16 nConst = getNodeCount(NT_const);
+
+ if ( nConst > 0 )
+ {
+ RTTypeClass typeClass = RT_TYPE_MODULE;
+ if ( getNodeType() == NT_constants )
+ typeClass = RT_TYPE_CONSTANTS;
+
+ RegistryTypeWriter aBlob(pLoader->getApi(),
+ typeClass,
+ OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
+ OUString(), nConst, 0, 0);
+
+ aBlob.setDoku( getDocumentation() );
+ aBlob.setFileName( OStringToOUString(getFileName(), RTL_TEXTENCODING_UTF8));
+
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+ sal_uInt16 index = 0;
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_const &&
+ pDecl->isInMainfile() )
+ {
+ ((AstConstant*)pDecl)->dumpBlob(aBlob, index++);
+ }
+ iter++;
+ }
+
+ pBlob = aBlob.getBlop();
+ aBlobSize = aBlob.getBlopSize();
+
+ if (localKey.setValue(OUString(), RG_VALUETYPE_BINARY,
+ (RegValue)pBlob, aBlobSize))
+ {
+ fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName(), localKey.getRegistryName());
+ return sal_False;
+ }
+ } else
+ {
+ RTTypeClass typeClass = RT_TYPE_MODULE;
+ if ( getNodeType() == NT_constants )
+ typeClass = RT_TYPE_CONSTANTS;
+
+ RegistryTypeWriter aBlob(pLoader->getApi(),
+ typeClass,
+ OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
+ OUString(), 0, 0, 0);
+
+ aBlob.setDoku( getDocumentation() );
+ if ( getNodeType() == NT_constants )
+ aBlob.setFileName( OStringToOUString(getFileName(), RTL_TEXTENCODING_UTF8));
+
+ pBlob = aBlob.getBlop();
+ aBlobSize = aBlob.getBlopSize();
+
+ if ( getNodeType() != NT_root )
+ {
+ if (localKey.setValue(OUString(), RG_VALUETYPE_BINARY,
+ (RegValue)pBlob, aBlobSize))
+ {
+ fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName(), localKey.getRegistryName());
+ return sal_False;
+ }
+ }
+ }
+ return AstDeclaration::dump(rKey, pLoader);
+}
+
+sal_Bool AstTypeDef::dump(RegistryKey& rKey, RegistryTypeWriterLoader* pLoader)
+{
+ RegistryKey localKey;
+ if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
+ {
+ fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName().getStr(), rKey.getRegistryName().getStr());
+ return sal_False;
+ }
+
+ RegistryTypeWriter aBlob(pLoader->getApi(), RT_TYPE_TYPEDEF,
+ OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
+ OStringToOUString(getBaseType()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ 0, 0, 0);
+
+ aBlob.setDoku( getDocumentation() );
+ aBlob.setFileName( OStringToOUString(getFileName(), RTL_TEXTENCODING_UTF8));
+
+ const sal_uInt8* pBlob = aBlob.getBlop();
+ sal_uInt32 aBlobSize = aBlob.getBlopSize();
+
+ if (localKey.setValue(OUString(), RG_VALUETYPE_BINARY, (RegValue)pBlob, aBlobSize))
+ {
+ fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName(), localKey.getRegistryName());
+ return sal_False;
+ }
+
+ return sal_True;
+}
+
+sal_Bool AstService::dump(RegistryKey& rKey, RegistryTypeWriterLoader* pLoader)
+{
+ if ( !idlc()->getOptions()->isValid("-C") )
+ return sal_True;
+
+ RegistryKey localKey;
+ if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
+ {
+ fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName().getStr(), rKey.getRegistryName().getStr());
+ return sal_False;
+ }
+
+ sal_uInt16 nProperties = 0;
+ sal_uInt16 nIfaceMember = 0;
+ sal_uInt16 nServMember = 0;
+ sal_uInt16 nNeeds = 0;
+ sal_uInt16 nObserves = 0;
+ if ( nMembers() > 0 )
+ {
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ while ( iter != end )
+ {
+ switch ( (*iter)->getNodeType() )
+ {
+ case NT_property:
+ nProperties++;
+ break;
+ case NT_interface_member:
+ nIfaceMember++;
+ break;
+ case NT_service_member:
+ nServMember++;
+ break;
+ case NT_observes:
+ nObserves++;
+ break;
+ case NT_needs:
+ nNeeds++;
+ break;
+ }
+ iter++;
+ }
+ }
+ sal_uInt16 nReferences = nIfaceMember + nServMember + nObserves + nNeeds;
+
+ RegistryTypeWriter aBlob(pLoader->getApi(), RT_TYPE_SERVICE,
+ OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
+ OUString(), nProperties, 0, nReferences);
+
+ aBlob.setDoku( getDocumentation() );
+ aBlob.setFileName( OStringToOUString(getFileName(), RTL_TEXTENCODING_UTF8));
+
+ if ( nProperties || nReferences )
+ {
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+ sal_uInt16 propertyIndex = 0;
+ sal_uInt16 referenceIndex = 0;
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ switch ( pDecl->getNodeType() )
+ {
+ case NT_property:
+ ((AstAttribute*)pDecl)->dumpBlob(aBlob, propertyIndex++);
+ break;
+ case NT_interface_member:
+ {
+ AstInterfaceMember* pIfaceMember = (AstInterfaceMember*)pDecl;
+ sal_uInt16 access = (pIfaceMember->isOptional() ? RT_ACCESS_OPTIONAL : RT_ACCESS_INVALID);
+ aBlob.setReferenceData(referenceIndex++,
+ OStringToOUString( pIfaceMember->getRealInterface()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ RT_REF_SUPPORTS, pIfaceMember->getDocumentation(), access);
+ }
+ break;
+ case NT_service_member:
+ {
+ AstServiceMember* pServMember = (AstServiceMember*)pDecl;
+ aBlob.setReferenceData(referenceIndex++,
+ OStringToOUString( pServMember->getRealService()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ RT_REF_EXPORTS, pServMember->getDocumentation());
+ }
+ break;
+ case NT_observes:
+ {
+ AstObserves* pObserves = (AstObserves*)pDecl;
+ aBlob.setReferenceData(referenceIndex++,
+ OStringToOUString( pObserves->getRealInterface()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ RT_REF_OBSERVES, pObserves->getDocumentation());
+ }
+ break;
+ case NT_needs:
+ {
+ AstNeeds* pNeeds = (AstNeeds*)pDecl;
+ aBlob.setReferenceData(referenceIndex++,
+ OStringToOUString( pNeeds->getRealService()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ RT_REF_NEEDS, pNeeds->getDocumentation());
+ }
+ break;
+ }
+ iter++;
+ }
+
+ const sal_uInt8* pBlob = aBlob.getBlop();
+ sal_uInt32 aBlobSize = aBlob.getBlopSize();
+
+ if (localKey.setValue(OUString(), RG_VALUETYPE_BINARY,
+ (RegValue)pBlob, aBlobSize))
+ {
+ fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName(), localKey.getRegistryName());
+ return sal_False;
+ }
+ }
+
+ return sal_True;
+}
+
+sal_Bool AstAttribute::dumpBlob(RegistryTypeWriter& rBlob, sal_uInt16 index)
+{
+ RTFieldAccess accessMode = RT_ACCESS_INVALID;
+
+ if (isReadonly())
+ {
+ accessMode |= RT_ACCESS_READONLY;
+ } else
+ {
+ accessMode |= RT_ACCESS_READWRITE;
+ }
+ if (isOptional())
+ {
+ accessMode |= RT_ACCESS_OPTIONAL;
+ }
+ if (isBound())
+ {
+ accessMode |= RT_ACCESS_BOUND;
+ }
+ if (isMayBeVoid())
+ {
+ accessMode |= RT_ACCESS_MAYBEVOID;
+ }
+ if (isConstrained())
+ {
+ accessMode |= RT_ACCESS_CONSTRAINED;
+ }
+ if (isTransient())
+ {
+ accessMode |= RT_ACCESS_TRANSIENT;
+ }
+ if (isMayBeAmbiguous())
+ {
+ accessMode |= RT_ACCESS_MAYBEAMBIGUOUS;
+ }
+ if (isMayBeDefault())
+ {
+ accessMode |= RT_ACCESS_MAYBEDEFAULT;
+ }
+ if (isRemoveable())
+ {
+ accessMode |= RT_ACCESS_REMOVEABLE;
+ }
+
+ rBlob.setFieldData(index, OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8),
+ OStringToOUString(getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ getDocumentation(), OUString(), accessMode);
+
+ return sal_True;
+}
+
+AstType* SAL_CALL resolveTypeDef(AstType* pType)
+{
+ if ( pType->getNodeType() == NT_typedef )
+ {
+ return resolveTypeDef(((AstTypeDef*)pType)->getBaseType());
+ }
+ return pType;
+}
+
+const sal_Char* AstSequence::getRelativName()
+{
+ if ( !m_pRelativName )
+ {
+ m_pRelativName = new OString("[]");
+ AstType* pType = resolveTypeDef( m_pMemberType );
+ *m_pRelativName += pType->getRelativName();
+ }
+
+ return m_pRelativName->getStr();
+}
diff --git a/idlc/source/astenum.cxx b/idlc/source/astenum.cxx
new file mode 100644
index 000000000000..ea9365d5c4cd
--- /dev/null
+++ b/idlc/source/astenum.cxx
@@ -0,0 +1,161 @@
+/*************************************************************************
+ *
+ * $RCSfile: astenum.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTENUM_HXX_
+#include <idlc/astenum.hxx>
+#endif
+
+using namespace ::rtl;
+
+AstEnum::AstEnum(const ::rtl::OString& name, AstScope* pScope)
+ : AstType(NT_enum, name, pScope)
+ , AstScope(NT_enum)
+ , m_enumValueCount(0)
+{
+}
+
+AstEnum::~AstEnum()
+{
+}
+
+AstConstant* AstEnum::checkValue(AstExpression* pExpr)
+{
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstConstant* pConst = NULL;
+ AstDeclaration* pDecl = NULL;
+
+ while ( iter != end)
+ {
+ pDecl = *iter;
+ pConst = (AstConstant*)pDecl;
+
+ if (pConst->getConstValue()->compare(pExpr))
+ return pConst;
+
+ iter++;
+ }
+
+ if ( pExpr->getExprValue()->u.lval > m_enumValueCount )
+ m_enumValueCount = pExpr->getExprValue()->u.lval + 1;
+
+ return NULL;
+}
+
+sal_Bool AstEnum::dump(RegistryKey& rKey, RegistryTypeWriterLoader* pLoader)
+{
+ RegistryKey localKey;
+ if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
+ {
+ fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName().getStr(), rKey.getRegistryName().getStr());
+ return sal_False;
+ }
+
+ sal_uInt16 nConst = getNodeCount(NT_enum_val);
+ if ( nConst > 0 )
+ {
+ RegistryTypeWriter aBlob(pLoader->getApi(),
+ RT_TYPE_ENUM,
+ OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
+ OUString(), nConst, 0, 0);
+
+ aBlob.setDoku( getDocumentation() );
+ aBlob.setFileName( OStringToOUString(getFileName(), RTL_TEXTENCODING_UTF8));
+
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+ sal_uInt16 index = 0;
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_enum_val )
+ ((AstConstant*)pDecl)->dumpBlob(aBlob, index++);
+
+ iter++;
+ }
+
+ const sal_uInt8* pBlob = aBlob.getBlop();
+ sal_uInt32 aBlobSize = aBlob.getBlopSize();
+
+ if (localKey.setValue(OUString(), RG_VALUETYPE_BINARY,
+ (RegValue)pBlob, aBlobSize))
+ {
+ fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName(), localKey.getRegistryName());
+ return sal_False;
+ }
+ }
+
+ return sal_True;
+}
+
+AstDeclaration* AstEnum::addDeclaration(AstDeclaration* pDecl)
+{
+ AstScope* pScope = getScope();
+ // add enum value to enclosing scope of the enum
+// pDecl->setName(scopeAsDecl(pScope)->getScopedName() + "::" + pDecl->getLocalName());
+// pScope->addDeclaration(pDecl);
+
+ return AstScope::addDeclaration(pDecl);
+}
diff --git a/idlc/source/astexpression.cxx b/idlc/source/astexpression.cxx
new file mode 100644
index 000000000000..8bc9d06e87d0
--- /dev/null
+++ b/idlc/source/astexpression.cxx
@@ -0,0 +1,1638 @@
+/*************************************************************************
+ *
+ * $RCSfile: astexpression.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTEXPRESSION_HXX_
+#include <idlc/astexpression.hxx>
+#endif
+#ifndef _IDLC_ASTCONSTANT_HXX_
+#include <idlc/astconstant.hxx>
+#endif
+#ifndef _IDLC_ASTSCOPE_HXX_
+#include <idlc/astscope.hxx>
+#endif
+#ifndef _IDLC_ERRORHANDLER_HXX_
+#include <idlc/errorhandler.hxx>
+#endif
+
+#include <limits.h>
+#include <float.h>
+
+#undef MAXCHAR
+#define MAXCHAR 127
+#undef MINCHAR
+#define MINCHAR -128
+
+#define MAXINT64 9223372036854775807
+#define MININT64 -9223372036854775807-1
+#define MAXUINT64 18446744073709551615
+
+using namespace ::rtl;
+
+AstExpression::AstExpression(AstExpression *pExpr, ExprType et)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = pExpr->coerce(et);
+ if ( !m_exprValue)
+ {
+ idlc()->error()->coercionError(pExpr, et);
+ }
+}
+
+AstExpression::AstExpression(ExprComb c, AstExpression *pExpr1, AstExpression *pExpr2)
+ : m_combOperator(c)
+ , m_subExpr1(pExpr1)
+ , m_subExpr2(pExpr2)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+}
+
+AstExpression::AstExpression(sal_Int16 s)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_short;
+ m_exprValue->u.sval = s;
+}
+
+AstExpression::AstExpression(sal_uInt16 us)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_ushort;
+ m_exprValue->u.usval = us;
+}
+
+AstExpression::AstExpression(sal_Int32 l)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_long;
+ m_exprValue->u.lval = l;
+}
+
+AstExpression::AstExpression(sal_Int32 l, ExprType et)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = et;
+ m_exprValue->u.lval = l;
+}
+
+AstExpression::AstExpression(sal_uInt32 ul)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_ulong;
+ m_exprValue->u.ulval = ul;
+}
+
+AstExpression::AstExpression(sal_Int64 h)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_hyper;
+ m_exprValue->u.hval = h;
+}
+
+AstExpression::AstExpression(sal_uInt64 uh)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_uhyper;
+ m_exprValue->u.uhval = uh;
+}
+
+AstExpression::AstExpression(float f)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_float;
+ m_exprValue->u.fval = f;
+}
+
+AstExpression::AstExpression(double d)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_double;
+ m_exprValue->u.dval = d;
+}
+
+AstExpression::AstExpression(sal_Char c)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_char;
+ m_exprValue->u.cval = c;
+}
+
+AstExpression::AstExpression(::rtl::OString* s, sal_Bool bIsScopedName)
+ : m_combOperator(EC_none)
+ , m_subExpr1(NULL)
+ , m_subExpr2(NULL)
+ , m_exprValue(NULL)
+ , m_pSymbolicName(NULL)
+{
+ fillDefinitionDetails();
+
+ if ( bIsScopedName )
+ {
+ m_pSymbolicName = s;
+ m_combOperator = EC_symbol;
+ } else
+ {
+ m_exprValue = new AstExprValue();
+ m_exprValue->et = ET_string;
+ m_exprValue->u.strval = s;
+ }
+}
+
+AstExpression::~AstExpression()
+{
+ if ( m_exprValue )
+ delete m_exprValue;
+ if ( m_subExpr1 )
+ delete m_subExpr1;
+ if ( m_subExpr2 )
+ delete m_subExpr2;
+ if ( m_pSymbolicName )
+ delete m_pSymbolicName;
+}
+
+/*
+ * Perform the coercion from the given AstExprValue to the requested
+ * ExprType. Return an AstExprValue if successful, NULL if failed.
+ * must be done for hyper, uhyper
+ */
+static AstExprValue *
+coerce_value(AstExprValue *ev, ExprType t)
+{
+ if (ev == NULL)
+ return NULL;
+
+ switch (t)
+ {
+ case ET_short:
+ switch (ev->et)
+ {
+ case ET_short:
+ return ev;
+ case ET_ushort:
+ if ((sal_uInt16)ev->u.usval > SHRT_MAX)
+ return NULL;
+ ev->u.sval = (sal_Int16)ev->u.usval;
+ ev->et = ET_short;
+ return ev;
+ case ET_long:
+ if ((sal_Int16)ev->u.lval > SHRT_MAX || (sal_Int16)ev->u.lval < SHRT_MIN)
+ return NULL;
+ ev->u.sval = (sal_Int16)ev->u.lval;
+ ev->et = ET_short;
+ return ev;
+ case ET_ulong:
+ if ((sal_Int16)ev->u.ulval > SHRT_MAX)
+ return NULL;
+ ev->u.sval = (sal_Int16)ev->u.ulval;
+ ev->et = ET_short;
+ return ev;
+ case ET_hyper:
+ if ((sal_Int16)ev->u.hval > SHRT_MAX || (sal_Int16)ev->u.hval < SHRT_MIN)
+ return NULL;
+ ev->u.sval = (sal_Int16)ev->u.hval;
+ ev->et = ET_short;
+ return ev;
+ case ET_uhyper:
+ if ((sal_Int16)ev->u.uhval > SHRT_MAX)
+ return NULL;
+ ev->u.sval = (sal_Int16)ev->u.uhval;
+ ev->et = ET_short;
+ return ev;
+ case ET_boolean:
+ ev->u.sval = (sal_Int16)ev->u.bval;
+ ev->et = ET_short;
+ return ev;
+ case ET_float:
+ if ((sal_Int16)ev->u.fval > SHRT_MAX || (sal_Int16)ev->u.fval < SHRT_MIN)
+ return NULL;
+ ev->u.sval = (sal_Int16)ev->u.fval;
+ ev->et = ET_short;
+ return ev;
+ case ET_double:
+ if ((sal_Int16)ev->u.dval > SHRT_MAX || (sal_Int16)ev->u.dval < SHRT_MIN)
+ return NULL;
+ ev->u.sval = (sal_Int16)ev->u.dval;
+ ev->et = ET_short;
+ return ev;
+ case ET_char:
+ ev->u.sval = (sal_Int16)ev->u.cval;
+ ev->et = ET_short;
+ return ev;
+ case ET_byte:
+ ev->u.sval = (sal_Int16)ev->u.byval;
+ ev->et = ET_short;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_ushort:
+ switch (ev->et)
+ {
+ case ET_short:
+ if (ev->u.sval < 0 && ev->u.sval != USHRT_MAX)
+ return NULL;
+ ev->u.usval = (sal_uInt16)ev->u.sval;
+ ev->et = ET_ushort;
+ return ev;
+ case ET_ushort:
+ return ev;
+ case ET_long:
+ if ((sal_uInt16)ev->u.lval > USHRT_MAX || ev->u.lval < 0)
+ return NULL;
+ ev->u.usval = (sal_uInt16)ev->u.lval;
+ ev->et = ET_ushort;
+ return ev;
+ case ET_ulong:
+ if ((sal_uInt16)ev->u.ulval > USHRT_MAX)
+ return NULL;
+ ev->u.usval = (sal_uInt16)ev->u.ulval;
+ ev->et = ET_ushort;
+ return ev;
+ case ET_hyper:
+ if ((sal_uInt16)ev->u.hval > USHRT_MAX || ev->u.hval < 0)
+ return NULL;
+ ev->u.usval = (sal_uInt16)ev->u.hval;
+ ev->et = ET_ushort;
+ return ev;
+ case ET_uhyper:
+ if ((sal_uInt16)ev->u.uhval > USHRT_MAX)
+ return NULL;
+ ev->u.usval = (sal_uInt16)ev->u.uhval;
+ ev->et = ET_ushort;
+ return ev;
+ case ET_boolean:
+ ev->u.usval = (sal_uInt16)ev->u.bval;
+ ev->et = ET_short;
+ return ev;
+ case ET_float:
+ if (ev->u.fval < 0.0 || (sal_uInt16)ev->u.fval > USHRT_MAX)
+ return NULL;
+ ev->u.usval = (sal_uInt16)ev->u.fval;
+ ev->et = ET_short;
+ return ev;
+ case ET_double:
+ if (ev->u.dval < 0.0 || (sal_uInt16)ev->u.dval > USHRT_MAX)
+ return NULL;
+ ev->u.usval = (sal_uInt16)ev->u.dval;
+ ev->et = ET_short;
+ return ev;
+ case ET_char:
+ if (ev->u.cval < 0)
+ return NULL;
+ ev->u.usval = (sal_uInt16)ev->u.cval;
+ ev->et = ET_ushort;
+ return ev;
+ case ET_byte:
+ ev->u.usval = (sal_uInt16)ev->u.byval;
+ ev->et = ET_ushort;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_long:
+ switch (ev->et)
+ {
+ case ET_short:
+ ev->u.lval = (sal_Int32)ev->u.sval;
+ ev->et = ET_long;
+ return ev;
+ case ET_ushort:
+ ev->u.lval = (sal_Int32)ev->u.usval;
+ ev->et = ET_long;
+ return ev;
+ case ET_long:
+ return ev;
+ case ET_ulong:
+ if ((sal_Int32)ev->u.ulval > LONG_MAX)
+ return NULL;
+ ev->u.lval = (sal_Int32)ev->u.ulval;
+ ev->et = ET_long;
+ return ev;
+ case ET_hyper:
+ if ((sal_Int32)ev->u.hval > LONG_MAX || (sal_Int32)ev->u.hval < LONG_MIN)
+ return NULL;
+ ev->u.lval = (sal_Int32)ev->u.hval;
+ ev->et = ET_long;
+ return ev;
+ case ET_uhyper:
+ if ((sal_Int32)ev->u.uhval > LONG_MAX)
+ return NULL;
+ ev->u.lval = (sal_Int32)ev->u.uhval;
+ ev->et = ET_long;
+ return ev;
+ case ET_boolean:
+ ev->u.lval = (sal_Int32)ev->u.bval;
+ ev->et = ET_long;
+ return ev;
+ case ET_float:
+ if ((sal_Int32)ev->u.fval > LONG_MAX || (sal_Int32)ev->u.fval < LONG_MIN)
+ return NULL;
+ ev->u.lval = (sal_Int32)ev->u.fval;
+ ev->et = ET_long;
+ return ev;
+ case ET_double:
+ if ((sal_Int32)ev->u.dval > LONG_MAX || (sal_Int32)ev->u.dval < LONG_MIN)
+ return NULL;
+ ev->u.lval = (sal_Int32)ev->u.dval;
+ ev->et = ET_long;
+ return ev;
+ case ET_char:
+ ev->u.lval = (sal_Int32) ev->u.cval;
+ ev->et = ET_long;
+ return ev;
+ case ET_byte:
+ ev->u.lval = (sal_Int32) ev->u.byval;
+ ev->et = ET_long;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_ulong:
+ switch (ev->et)
+ {
+ case ET_short:
+ if (ev->u.sval < 0)
+ return NULL;
+ ev->u.ulval = (sal_uInt32)ev->u.sval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_ushort:
+ ev->u.ulval = (sal_uInt32)ev->u.usval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_long:
+ if ((sal_uInt32)ev->u.lval < 0 && (sal_uInt32)ev->u.lval != ULONG_MAX)
+ return NULL;
+ ev->u.ulval = (sal_uInt32)ev->u.lval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_ulong:
+ return ev;
+ case ET_hyper:
+ if (ev->u.hval > (sal_Int64)ULONG_MAX || ev->u.hval < 0)
+ return NULL;
+ ev->u.lval = (sal_uInt32)ev->u.hval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_uhyper:
+ if (ev->u.uhval > (sal_uInt64)ULONG_MAX)
+ return NULL;
+ ev->u.ulval = (sal_uInt32)ev->u.uhval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_boolean:
+ ev->u.ulval = (sal_uInt32)ev->u.bval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_float:
+ if (ev->u.fval < 0.0 || (sal_uInt32)ev->u.fval > ULONG_MAX)
+ return NULL;
+ ev->u.ulval = (sal_uInt32)ev->u.fval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_double:
+ if (ev->u.dval < 0.0 || (sal_uInt32)ev->u.dval > ULONG_MAX)
+ return NULL;
+ ev->u.ulval = (sal_uInt32)ev->u.dval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_char:
+ if (ev->u.cval < 0)
+ return NULL;
+ ev->u.ulval = (sal_uInt32)ev->u.cval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_byte:
+ ev->u.ulval = (sal_uInt32)ev->u.byval;
+ ev->et = ET_ulong;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_hyper:
+ switch (ev->et)
+ {
+ case ET_short:
+ ev->u.hval = (sal_Int64)ev->u.sval;
+ ev->et = ET_hyper;
+ return ev;
+ case ET_ushort:
+ ev->u.hval = (sal_Int64)ev->u.usval;
+ ev->et = ET_hyper;
+ return ev;
+ case ET_long:
+ ev->u.hval = (sal_Int64)ev->u.lval;
+ ev->et = ET_hyper;
+ return ev;
+ case ET_ulong:
+ ev->u.hval = (sal_Int64)ev->u.ulval;
+ ev->et = ET_hyper;
+ return ev;
+ case ET_hyper:
+ return ev;
+ case ET_uhyper:
+ if (ev->u.uhval > (sal_uInt64)MAXINT64)
+ return NULL;
+ ev->u.hval = (sal_Int64)ev->u.uhval;
+ ev->et = ET_long;
+ return ev;
+ case ET_boolean:
+ ev->u.hval = (sal_Int64)ev->u.bval;
+ ev->et = ET_hyper;
+ return ev;
+ case ET_float:
+ if ((sal_Int64)ev->u.fval > MAXINT64 || (sal_Int64)ev->u.fval < MININT64)
+ return NULL;
+ ev->u.hval = (sal_Int64)ev->u.fval;
+ ev->et = ET_hyper;
+ return ev;
+ case ET_double:
+ if ((sal_Int64)ev->u.dval > MAXINT64 || (sal_Int64)ev->u.dval < MININT64)
+ return NULL;
+ ev->u.hval = (sal_Int64)ev->u.dval;
+ ev->et = ET_hyper;
+ return ev;
+ case ET_char:
+ ev->u.hval = (sal_Int64)ev->u.cval;
+ ev->et = ET_hyper;
+ return ev;
+ case ET_byte:
+ ev->u.hval = (sal_Int64)ev->u.byval;
+ ev->et = ET_hyper;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_uhyper:
+ switch (ev->et)
+ {
+ case ET_short:
+ if (ev->u.sval < 0)
+ return NULL;
+ ev->u.uhval = (sal_uInt64)ev->u.sval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_ushort:
+ ev->u.uhval = (sal_uInt64)ev->u.usval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_long:
+ if ((sal_uInt64)ev->u.lval < 0 && ev->u.lval != MAXUINT64)
+ return NULL;
+ ev->u.uhval = (sal_uInt64)ev->u.lval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_ulong:
+ ev->u.uhval = (sal_uInt64)ev->u.ulval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_hyper:
+ if ((sal_uInt64)ev->u.hval < 0 && ev->u.hval != MAXUINT64)
+ return NULL;
+ ev->u.uhval = (sal_uInt64)ev->u.hval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_uhyper:
+ return ev;
+ case ET_boolean:
+ ev->u.uhval = (sal_uInt64)ev->u.bval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_float:
+ if (ev->u.fval < 0.0 || (sal_uInt64)ev->u.fval > MAXUINT64)
+ return NULL;
+ ev->u.uhval = (sal_uInt64)ev->u.fval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_double:
+ if (ev->u.dval < 0.0 || (sal_uInt64)ev->u.dval > MAXUINT64)
+ return NULL;
+ ev->u.uhval = (sal_uInt64)ev->u.dval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_char:
+ if (ev->u.cval < 0)
+ return NULL;
+ ev->u.uhval = (sal_uInt64)ev->u.cval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_byte:
+ ev->u.uhval = (sal_uInt64)ev->u.byval;
+ ev->et = ET_uhyper;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_boolean:
+ switch (ev->et)
+ {
+ case ET_short:
+ ev->u.bval = (ev->u.sval == 0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_ushort:
+ ev->u.bval = (ev->u.usval == 0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_long:
+ ev->u.bval = (ev->u.lval == 0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_ulong:
+ ev->u.bval = (ev->u.ulval == 0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_hyper:
+ ev->u.bval = (ev->u.hval == 0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_uhyper:
+ ev->u.bval = (ev->u.uhval == 0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_boolean:
+ return ev;
+ case ET_float:
+ ev->u.bval = (ev->u.fval == 0.0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_double:
+ ev->u.bval = (ev->u.dval == 0.0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_char:
+ ev->u.bval = (ev->u.cval == 0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_byte:
+ ev->u.bval = (ev->u.byval == 0) ? sal_False : sal_True;
+ ev->et = ET_boolean;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_float:
+ switch (ev->et)
+ {
+ case ET_short:
+ ev->u.fval = (float)ev->u.sval;
+ ev->et = ET_float;
+ return ev;
+ case ET_ushort:
+ ev->u.fval = (float)ev->u.usval;
+ ev->et = ET_float;
+ return ev;
+ case ET_long:
+ ev->u.fval = (float)ev->u.lval;
+ ev->et = ET_float;
+ return ev;
+ case ET_ulong:
+ ev->u.fval = (float)ev->u.ulval;
+ ev->et = ET_float;
+ return ev;
+ case ET_hyper:
+ ev->u.fval = (float)ev->u.hval;
+ ev->et = ET_float;
+ return ev;
+ case ET_uhyper:
+ if ((float)ev->u.ulval > FLT_MAX)
+ return NULL;
+ ev->u.fval = (float)ev->u.ulval;
+ ev->et = ET_float;
+ return ev;
+ return NULL;
+ case ET_boolean:
+ ev->u.fval = (ev->u.bval == sal_True) ? 1.0f : 0.0f;
+ ev->et = ET_float;
+ return ev;
+ case ET_float:
+ return ev;
+ case ET_double:
+ if ((float)ev->u.dval > FLT_MAX || (float)ev->u.dval < -FLT_MAX)
+ return NULL;
+ ev->u.fval = (float)ev->u.dval;
+ ev->et = ET_float;
+ return ev;
+ case ET_char:
+ ev->u.fval = (float)ev->u.cval;
+ ev->et = ET_float;
+ return ev;
+ case ET_byte:
+ ev->u.fval = (float)ev->u.byval;
+ ev->et = ET_float;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_double:
+ switch (ev->et)
+ {
+ case ET_short:
+ ev->u.dval = (double)ev->u.sval;
+ ev->et = ET_double;
+ return ev;
+ case ET_ushort:
+ ev->u.dval = (double)ev->u.usval;
+ ev->et = ET_double;
+ return ev;
+ case ET_long:
+ ev->u.dval = (double)ev->u.lval;
+ ev->et = ET_double;
+ return ev;
+ case ET_ulong:
+ ev->u.dval = (double)ev->u.ulval;
+ ev->et = ET_double;
+ return ev;
+ case ET_hyper:
+ ev->u.dval = (double)ev->u.hval;
+ ev->et = ET_double;
+ return ev;
+ case ET_uhyper:
+ if ((double)ev->u.dval > FLT_MAX || (double)ev->u.dval < -FLT_MAX)
+ return NULL;
+ ev->u.dval = (double)ev->u.ulval;
+ ev->et = ET_double;
+ return ev;
+ case ET_boolean:
+ ev->u.dval = (ev->u.bval == sal_True) ? 1.0 : 0.0;
+ ev->et = ET_double;
+ return ev;
+ case ET_float:
+ ev->u.dval = (double)ev->u.fval;
+ ev->et = ET_double;
+ return ev;
+ case ET_double:
+ return ev;
+ case ET_char:
+ ev->u.dval = (double)ev->u.cval;
+ ev->et = ET_double;
+ return ev;
+ case ET_byte:
+ ev->u.dval = (double)ev->u.byval;
+ ev->et = ET_double;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_char:
+ switch (ev->et)
+ {
+ case ET_short:
+ if ((sal_Char)ev->u.sval > MAXCHAR || (sal_Char)ev->u.sval < MINCHAR)
+ return NULL;
+ ev->u.cval = (sal_Char)ev->u.sval;
+ ev->et = ET_char;
+ return ev;
+ case ET_ushort:
+ if ((sal_Char)ev->u.usval > MAXCHAR)
+ return NULL;
+ ev->u.cval = (sal_Char)ev->u.usval;
+ ev->et = ET_char;
+ return ev;
+ case ET_long:
+ if ((sal_Char)ev->u.lval > MAXCHAR || (sal_Char)ev->u.lval < MINCHAR)
+ return NULL;
+ ev->u.cval = (sal_Char)ev->u.lval;
+ ev->et = ET_char;
+ return ev;
+ case ET_ulong:
+ if ((sal_Char)ev->u.ulval > MAXCHAR)
+ return NULL;
+ ev->u.cval = (sal_Char)ev->u.ulval;
+ ev->et = ET_char;
+ return ev;
+ case ET_hyper:
+ if ((sal_Char)ev->u.hval > MAXCHAR || (sal_Char)ev->u.hval < MINCHAR)
+ return NULL;
+ ev->u.cval = (sal_Char)ev->u.hval;
+ ev->et = ET_char;
+ return ev;
+ case ET_uhyper:
+ if ((sal_Char)ev->u.ulval > MAXCHAR)
+ return NULL;
+ ev->u.cval = (sal_Char)ev->u.uhval;
+ ev->et = ET_char;
+ return ev;
+ case ET_boolean:
+ ev->u.cval = (sal_Char)ev->u.bval;
+ ev->et = ET_char;
+ return ev;
+ case ET_float:
+ if ((sal_Char)ev->u.fval > MAXCHAR || (sal_Char)ev->u.fval < MINCHAR)
+ return NULL;
+ ev->u.cval = (sal_Char)ev->u.fval;
+ ev->et = ET_char;
+ return ev;
+ case ET_double:
+ if ((sal_Char)ev->u.dval > MAXCHAR || (sal_Char)ev->u.dval < MINCHAR)
+ return NULL;
+ ev->u.cval = (sal_Char)ev->u.dval;
+ ev->et = ET_char;
+ return ev;
+ case ET_char:
+ return ev;
+ case ET_byte:
+ if ((sal_Char)ev->u.byval > MAXCHAR)
+ return NULL;
+ ev->u.cval = (sal_Char)ev->u.byval;
+ ev->et = ET_char;
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_byte:
+ switch (ev->et)
+ {
+ case ET_short:
+ if (ev->u.sval < 0 || (sal_uChar)ev->u.sval > (MAXCHAR << 1))
+ return NULL;
+ ev->u.byval = (sal_uChar)ev->u.sval;
+ ev->et = ET_byte;
+ return ev;
+ case ET_ushort:
+ if ((sal_uChar)ev->u.usval > (MAXCHAR << 1))
+ return NULL;
+ ev->u.byval = (sal_uChar)ev->u.usval;
+ ev->et = ET_byte;
+ return ev;
+ case ET_long:
+ if (ev->u.lval < 0 || (sal_uChar)ev->u.lval > (MAXCHAR << 1))
+ return NULL;
+ ev->u.byval = (sal_uChar) ev->u.lval;
+ ev->et = ET_byte;
+ return ev;
+ case ET_ulong:
+ if ((sal_uChar)ev->u.ulval > (MAXCHAR << 1))
+ return NULL;
+ ev->u.byval = (sal_uChar) ev->u.ulval;
+ ev->et = ET_byte;
+ return ev;
+ case ET_hyper:
+ if (ev->u.hval < 0 || (sal_uChar)ev->u.hval > (MAXCHAR << 1))
+ return NULL;
+ ev->u.byval = (sal_uChar) ev->u.hval;
+ ev->et = ET_byte;
+ return ev;
+ case ET_uhyper:
+ if ((sal_uChar)ev->u.uhval > (MAXCHAR << 1))
+ return NULL;
+ ev->u.byval = (sal_uChar) ev->u.uhval;
+ ev->et = ET_byte;
+ return ev;
+ case ET_boolean:
+ ev->u.byval = (ev->u.bval == sal_False) ? 1 : 0;
+ ev->et = ET_byte;
+ return ev;
+ case ET_float:
+ if (ev->u.fval < 0.0 || (sal_uChar)ev->u.fval > (MAXCHAR << 1))
+ return NULL;
+ ev->u.byval = (sal_uChar) ev->u.fval;
+ ev->et = ET_byte;
+ return ev;
+ case ET_double:
+ if (ev->u.dval < 0.0 || (sal_uChar)ev->u.dval > (MAXCHAR << 1))
+ return NULL;
+ ev->u.byval = (sal_uChar) ev->u.dval;
+ ev->et = ET_byte;
+ return ev;
+ case ET_char:
+ if (ev->u.cval < 0)
+ return NULL;
+ ev->u.byval = (sal_uChar) ev->u.cval;
+ ev->et = ET_byte;
+ return ev;
+ case ET_byte:
+ return ev;
+ case ET_string:
+ case ET_any:
+ case ET_void:
+ case ET_type:
+ case ET_none:
+ return NULL;
+ }
+ case ET_any:
+ switch (ev->et)
+ {
+ case ET_any:
+ return ev;
+ default:
+ return NULL;
+ }
+ case ET_void:
+ switch (ev->et)
+ {
+ case ET_void:
+ return ev;
+ default:
+ return NULL;
+ }
+ case ET_type:
+ switch (ev->et)
+ {
+ case ET_type:
+ return ev;
+ default:
+ return NULL;
+ }
+ case ET_none:
+ return NULL;
+ case ET_string:
+ switch (ev->et)
+ {
+ case ET_string:
+ return ev;
+ default:
+ return NULL;
+ }
+ }
+
+ return NULL;
+}
+
+/*
+ * Evaluate the expression with the evaluation kind requested. Supported
+ * evaluation kinds are
+ * - EK_const: The expression must evaluate to a constant
+ * - EK_positive_int: The expression must further evaluate to a
+ * positive integer
+ */
+static AstExprValue *
+eval_kind(AstExprValue *ev, EvalKind ek)
+{
+ if (ek == EK_const)
+ return ev;
+ if (ek == EK_positive_int)
+ return coerce_value(ev, ET_ulong);
+
+ return NULL;
+}
+
+
+
+AstExprValue* AstExpression::eval(EvalKind ek)
+{
+ AstExprValue *v = NULL;
+
+ /*
+ * Call internal evaluator which does not coerce value to
+ * EvalKind-expected format
+ */
+ v = eval_internal(ek);
+ /*
+ * Then coerce according to EvalKind-expected format
+ */
+ return eval_kind(v, ek);
+}
+
+AstExprValue* AstExpression::coerce(ExprType t, sal_Bool bAssign)
+{
+ AstExprValue *copy;
+
+ /*
+ * Is it already of the right type?
+ */
+ if (m_exprValue != NULL && m_exprValue->et == t)
+ return m_exprValue;
+ /*
+ * OK, must coerce
+ *
+ * First, evaluate it, then try to coerce result type
+ * If already evaluated, return the result
+ */
+ m_exprValue = eval_internal(EK_const);
+ if (m_exprValue == NULL)
+ return NULL;
+
+ /*
+ * Create a copy to contain coercion result
+ */
+ copy = new AstExprValue;
+
+ copy->et = m_exprValue->et;
+ switch (m_exprValue->et)
+ {
+ case ET_void:
+ case ET_none:
+ case ET_any:
+ return NULL;
+ case ET_short:
+ copy->u.sval = m_exprValue->u.sval;
+ break;
+ case ET_ushort:
+ copy->u.usval = m_exprValue->u.usval;
+ break;
+ case ET_long:
+ copy->u.lval = m_exprValue->u.lval;
+ break;
+ case ET_ulong:
+ copy->u.ulval = m_exprValue->u.ulval;
+ break;
+ case ET_hyper:
+ copy->u.hval = m_exprValue->u.hval;
+ break;
+ case ET_uhyper:
+ copy->u.uhval = m_exprValue->u.uhval;
+ break;
+ case ET_boolean:
+ copy->u.bval = m_exprValue->u.bval;
+ break;
+ case ET_float:
+ copy->u.fval = m_exprValue->u.fval;
+ break;
+ case ET_double:
+ copy->u.dval = m_exprValue->u.dval;
+ break;
+ case ET_char:
+ copy->u.cval = m_exprValue->u.cval;
+ break;
+ case ET_byte:
+ copy->u.byval = m_exprValue->u.byval;
+ break;
+ case ET_string:
+ copy->u.strval = m_exprValue->u.strval;
+ break;
+ }
+
+ if (bAssign)
+ {
+ m_exprValue = coerce_value(copy, t);
+ return m_exprValue;
+ }
+
+ return coerce_value(copy, t);
+}
+
+void AstExpression::evaluate(EvalKind ek)
+{
+ m_exprValue = eval_internal(ek);
+ m_exprValue = eval_kind(m_exprValue, ek);
+}
+
+sal_Bool AstExpression::operator==(AstExpression *pExpr)
+{
+ if (m_combOperator != pExpr->getCombOperator())
+ return sal_False;
+ evaluate(EK_const);
+ pExpr->evaluate(EK_const);
+ if (m_exprValue == NULL || pExpr->getExprValue() == NULL)
+ return sal_False;
+ if (m_exprValue->et != pExpr->getExprValue()->et)
+ return sal_False;
+ switch (m_exprValue->et)
+ {
+ case ET_short:
+ return (m_exprValue->u.sval == pExpr->getExprValue()->u.sval) ? sal_True : sal_False;
+ case ET_ushort:
+ return (m_exprValue->u.usval == pExpr->getExprValue()->u.usval) ? sal_True : sal_False;
+ case ET_long:
+ return (m_exprValue->u.lval == pExpr->getExprValue()->u.lval) ? sal_True : sal_False;
+ case ET_ulong:
+ return (m_exprValue->u.ulval == pExpr->getExprValue()->u.ulval) ? sal_True : sal_False;
+ case ET_hyper:
+ return (m_exprValue->u.hval == pExpr->getExprValue()->u.hval) ? sal_True : sal_False;
+ case ET_uhyper:
+ return (m_exprValue->u.uhval == pExpr->getExprValue()->u.uhval) ? sal_True : sal_False;
+ case ET_float:
+ return (m_exprValue->u.fval == pExpr->getExprValue()->u.fval) ? sal_True : sal_False;
+ case ET_double:
+ return (m_exprValue->u.dval == pExpr->getExprValue()->u.dval) ? sal_True : sal_False;
+ case ET_char:
+ return (m_exprValue->u.cval == pExpr->getExprValue()->u.cval) ? sal_True : sal_False;
+ case ET_byte:
+ return (m_exprValue->u.byval == pExpr->getExprValue()->u.byval) ? sal_True : sal_False;
+ case ET_boolean:
+ return (m_exprValue->u.lval == pExpr->getExprValue()->u.lval) ? sal_True : sal_False;
+ case ET_string:
+ if (m_exprValue->u.strval == NULL)
+ {
+ if (pExpr->getExprValue()->u.strval == NULL)
+ return sal_True;
+ else
+ return sal_False;
+ } else
+ if (pExpr->getExprValue()->u.strval == NULL)
+ return sal_False;
+ else
+ return (m_exprValue->u.strval == pExpr->getExprValue()->u.strval) ? sal_True : sal_False;
+ case ET_any:
+ case ET_void:
+ case ET_none:
+ return sal_False;
+ }
+
+ return sal_False;
+}
+
+sal_Bool AstExpression::compare(AstExpression *pExpr)
+{
+ if (m_combOperator != pExpr->getCombOperator())
+ return sal_False;
+ evaluate(EK_const);
+ pExpr->evaluate(EK_const);
+ if (m_exprValue == NULL || pExpr->getExprValue() == NULL)
+ return sal_False;
+ if (m_exprValue->et != pExpr->getExprValue()->et)
+ return sal_False;
+ switch (m_exprValue->et)
+ {
+ case ET_short:
+ return (m_exprValue->u.sval == pExpr->getExprValue()->u.sval) ? sal_True : sal_False;
+ case ET_ushort:
+ return (m_exprValue->u.usval == pExpr->getExprValue()->u.usval) ? sal_True : sal_False;
+ case ET_long:
+ return (m_exprValue->u.lval == pExpr->getExprValue()->u.lval) ? sal_True : sal_False;
+ case ET_ulong:
+ return (m_exprValue->u.ulval == pExpr->getExprValue()->u.ulval) ? sal_True : sal_False;
+ case ET_hyper:
+ return (m_exprValue->u.hval == pExpr->getExprValue()->u.hval) ? sal_True : sal_False;
+ case ET_uhyper:
+ return (m_exprValue->u.uhval == pExpr->getExprValue()->u.uhval) ? sal_True : sal_False;
+ case ET_float:
+ return (m_exprValue->u.fval == pExpr->getExprValue()->u.fval) ? sal_True : sal_False;
+ case ET_double:
+ return (m_exprValue->u.dval == pExpr->getExprValue()->u.dval) ? sal_True : sal_False;
+ case ET_char:
+ return (m_exprValue->u.cval == pExpr->getExprValue()->u.cval) ? sal_True : sal_False;
+ case ET_byte:
+ return (m_exprValue->u.byval == pExpr->getExprValue()->u.byval) ? sal_True : sal_False;
+ case ET_boolean:
+ return (m_exprValue->u.lval == pExpr->getExprValue()->u.lval) ? sal_True : sal_False;
+ case ET_string:
+ if (m_exprValue->u.strval == NULL)
+ {
+ if (pExpr->getExprValue()->u.strval == NULL)
+ return sal_True;
+ else
+ return sal_False;
+ } else
+ if (pExpr->getExprValue()->u.strval == NULL)
+ return sal_False;
+ else
+ return (m_exprValue->u.strval == pExpr->getExprValue()->u.strval) ? sal_True : sal_False;
+ case ET_any:
+ case ET_void:
+ case ET_none:
+ return sal_False;
+ }
+
+ return sal_False;
+}
+
+void AstExpression::fillDefinitionDetails()
+{
+ m_pScope = idlc()->scopes()->depth() > 0 ? idlc()->scopes()->top() : NULL;
+ m_lineNo = idlc()->getLineNumber();
+ m_fileName = idlc()->getFileName();
+}
+
+AstExprValue* AstExpression::eval_internal(EvalKind ek)
+{
+ /*
+ * Already evaluated?
+ */
+ if ( m_exprValue != NULL )
+ return eval_kind(m_exprValue, ek);
+ /*
+ * OK, must evaluate operator
+ */
+ switch (m_combOperator)
+ {
+ case EC_add:
+ case EC_minus:
+ case EC_mul:
+ case EC_div:
+ case EC_mod:
+ m_exprValue = eval_bin_op(ek);
+ return eval_kind(m_exprValue, ek);
+ case EC_or:
+ case EC_xor:
+ case EC_and:
+ case EC_left:
+ case EC_right:
+ m_exprValue = eval_bit_op(ek);
+ return eval_kind(m_exprValue, ek);
+ case EC_u_plus:
+ case EC_u_minus:
+ case EC_bit_neg:
+ m_exprValue = eval_un_op(ek);
+ return eval_kind(m_exprValue, ek);
+ case EC_symbol:
+ m_exprValue = eval_symbol(ek);
+ return eval_kind(m_exprValue, ek);
+ case EC_none:
+ return NULL;
+ }
+
+ return NULL;
+}
+
+AstExprValue* AstExpression::eval_bin_op(EvalKind ek)
+{
+ AstExprValue *retval = NULL;
+ ExprType eType = ET_double;
+
+ if ( m_combOperator == EC_mod )
+ eType = ET_hyper;
+
+ if (ek != EK_const && ek != EK_positive_int)
+ return NULL;
+ if (m_subExpr1 == NULL || m_subExpr2 == NULL)
+ return NULL;
+ m_subExpr1->setExprValue(m_subExpr1->eval_internal(ek));
+ if (m_subExpr1->getExprValue() == NULL)
+ return NULL;
+ m_subExpr1->setExprValue(m_subExpr1->coerce(eType));
+ if (m_subExpr1->getExprValue() == NULL)
+ return NULL;
+ m_subExpr2->setExprValue(m_subExpr2->eval_internal(ek));
+ if (m_subExpr2->getExprValue() == NULL)
+ return NULL;
+ m_subExpr2->setExprValue(m_subExpr2->coerce(eType));
+ if (m_subExpr2->getExprValue() == NULL)
+ return NULL;
+
+ retval = new AstExprValue();
+ retval->et = eType;
+
+ switch (m_combOperator)
+ {
+ case EC_mod:
+ if (m_subExpr2->getExprValue()->u.hval == 0)
+ return NULL;
+ retval->u.hval = m_subExpr1->getExprValue()->u.hval % m_subExpr2->getExprValue()->u.hval;
+ break;
+ case EC_add:
+ retval->u.dval = m_subExpr1->getExprValue()->u.dval + m_subExpr2->getExprValue()->u.dval;
+ break;
+ case EC_minus:
+ retval->u.dval = m_subExpr1->getExprValue()->u.dval - m_subExpr2->getExprValue()->u.dval;
+ break;
+ case EC_mul:
+ retval->u.dval = m_subExpr1->getExprValue()->u.dval * m_subExpr2->getExprValue()->u.dval;
+ break;
+ case EC_div:
+ if (m_subExpr2->getExprValue()->u.dval == 0.0)
+ return NULL;
+ retval->u.dval = m_subExpr1->getExprValue()->u.dval / m_subExpr2->getExprValue()->u.dval;
+ break;
+ default:
+ return NULL;
+ }
+
+ return retval;
+}
+
+AstExprValue* AstExpression::eval_bit_op(EvalKind ek)
+{
+ AstExprValue *retval = NULL;
+
+ if (ek != EK_const && ek != EK_positive_int)
+ return NULL;
+ if (m_subExpr1 == NULL || m_subExpr2 == NULL)
+ return NULL;
+ m_subExpr1->setExprValue(m_subExpr1->eval_internal(ek));
+ if (m_subExpr1->getExprValue() == NULL)
+ return NULL;
+ m_subExpr1->setExprValue(m_subExpr1->coerce(ET_long));
+ if (m_subExpr1->getExprValue() == NULL)
+ return NULL;
+ m_subExpr2->setExprValue(m_subExpr2->eval_internal(ek));
+ if (m_subExpr2->getExprValue() == NULL)
+ return NULL;
+ m_subExpr2->setExprValue(m_subExpr2->coerce(ET_long));
+ if (m_subExpr2->getExprValue() == NULL)
+ return NULL;
+
+ retval = new AstExprValue;
+ retval->et = ET_long;
+
+ switch (m_combOperator)
+ {
+ case EC_or:
+ retval->u.lval = m_subExpr1->getExprValue()->u.lval | m_subExpr2->getExprValue()->u.lval;
+ break;
+ case EC_xor:
+ retval->u.lval = m_subExpr1->getExprValue()->u.lval ^ m_subExpr2->getExprValue()->u.lval;
+ break;
+ case EC_and:
+ retval->u.lval = m_subExpr1->getExprValue()->u.lval & m_subExpr2->getExprValue()->u.lval;
+ break;
+ case EC_left:
+ retval->u.lval = m_subExpr1->getExprValue()->u.lval << m_subExpr2->getExprValue()->u.lval;
+ break;
+ case EC_right:
+ retval->u.lval = m_subExpr1->getExprValue()->u.lval >> m_subExpr2->getExprValue()->u.lval;
+ break;
+ default:
+ return NULL;
+ }
+
+ return retval;
+}
+
+AstExprValue* AstExpression::eval_un_op(EvalKind ek)
+{
+ AstExprValue *retval = NULL;
+
+ if (m_exprValue != NULL)
+ return m_exprValue;
+
+ if (ek != EK_const && ek != EK_positive_int)
+ return NULL;
+ if (m_subExpr1 == NULL)
+ return NULL;
+ m_subExpr1->setExprValue(m_subExpr1->eval_internal(ek));
+ if (m_subExpr1->getExprValue() == NULL)
+ return NULL;
+ m_subExpr1->setExprValue(m_subExpr1->coerce(ET_double));
+ if (m_subExpr1->getExprValue() == NULL)
+ return NULL;
+
+ retval = new AstExprValue();
+ retval->et = ET_double;
+
+ switch (m_combOperator)
+ {
+ case EC_u_plus:
+ retval->u.lval = m_subExpr1->getExprValue()->u.lval;
+ break;
+ case EC_u_minus:
+ retval->u.lval = -(m_subExpr1->getExprValue()->u.lval);
+ break;
+ case EC_bit_neg:
+ m_subExpr1->setExprValue(m_subExpr1->coerce(ET_long));
+ if (m_subExpr1->getExprValue() == NULL)
+ return NULL;
+ retval->u.lval = ~m_subExpr1->getExprValue()->u.lval;
+ break;
+ default:
+ return NULL;
+ }
+
+ return retval;
+}
+
+AstExprValue* AstExpression::eval_symbol(EvalKind ek)
+{
+ AstScope *pScope;
+ AstDeclaration *pDecl;
+ AstConstant *pConst;
+
+ /*
+ * Is there a symbol stored?
+ */
+ if (m_pSymbolicName == NULL)
+ {
+ idlc()->error()->evalError(this);
+ return NULL;
+ }
+ /*
+ * Get current scope for lookup
+ */
+ if (idlc()->scopes()->depth() > 0)
+ pScope = idlc()->scopes()->topNonNull();
+ if ( !pScope )
+ {
+ idlc()->error()->lookupError(*m_pSymbolicName);
+ return NULL;
+ }
+ /*
+ * Do lookup
+ */
+ pDecl = pScope->lookupByName(*m_pSymbolicName);
+ if (pDecl == NULL)
+ {
+ idlc()->error()->lookupError(*m_pSymbolicName);
+ return NULL;
+ }
+ /*
+ * Is it a constant?
+ */
+ if (pDecl->getNodeType() != NT_const &&
+ pDecl->getNodeType() != NT_enum_val)
+ {
+ idlc()->error()->constantExpected(pDecl, *m_pSymbolicName);
+ return NULL;
+ }
+ /*
+ * OK, now evaluate the constant we just got, to produce its value
+ */
+ pConst = reinterpret_cast< AstConstant* >(pDecl);
+ if (pConst == NULL)
+ return NULL;
+ return pConst->getConstValue()->eval_internal(ek);
+}
+
+OString AstExpression::toString()
+{
+ OString exprStr;
+ if ( m_combOperator == EC_symbol )
+ return *m_pSymbolicName;
+
+ if ( m_exprValue )
+ {
+ switch (m_exprValue->et)
+ {
+ case ET_short:
+ return OString::valueOf((sal_Int32)m_exprValue->u.sval);
+ case ET_ushort:
+ return OString::valueOf((sal_Int32)m_exprValue->u.usval);
+ case ET_long:
+ return OString::valueOf(m_exprValue->u.lval);
+ case ET_ulong:
+ return OString::valueOf((sal_Int64)m_exprValue->u.ulval);
+ case ET_hyper:
+ return OString::valueOf(m_exprValue->u.hval);
+ case ET_uhyper:
+ return OString::valueOf((sal_Int64)m_exprValue->u.uhval);
+ case ET_float:
+ return OString::valueOf(m_exprValue->u.fval);
+ case ET_double:
+ return OString::valueOf(m_exprValue->u.dval);
+ case ET_char:
+ return OString::valueOf(m_exprValue->u.cval);
+ case ET_byte:
+ return OString::valueOf((sal_Int32)m_exprValue->u.byval);
+ case ET_boolean:
+ if ( m_exprValue->u.lval == 0)
+ return OString("FALSE");
+ else
+ return OString("TRUE");
+ case ET_string:
+ return *(m_exprValue->u.strval);
+ case ET_any:
+ case ET_void:
+ case ET_none:
+ return OString();
+ }
+ }
+
+ switch (m_combOperator)
+ {
+ case EC_u_plus:
+ exprStr += OString("+");
+ break;
+ case EC_u_minus:
+ exprStr += OString("-");
+ break;
+ case EC_bit_neg:
+ exprStr += OString("~");
+ }
+ if ( m_subExpr1 )
+ exprStr += m_subExpr1->toString();
+ switch (m_combOperator)
+ {
+ case EC_add:
+ exprStr += OString(" + ");
+ break;
+ case EC_minus:
+ exprStr += OString(" - ");
+ break;
+ case EC_mul:
+ exprStr += OString(" * ");
+ break;
+ case EC_div:
+ exprStr += OString(" / ");
+ break;
+ case EC_mod:
+ exprStr += OString(" % ");
+ break;
+ case EC_or:
+ exprStr += OString(" | ");
+ break;
+ case EC_xor:
+ exprStr += OString(" ^ ");
+ break;
+ case EC_and:
+ exprStr += OString(" & ");
+ break;
+ case EC_left:
+ exprStr += OString(" << ");
+ break;
+ case EC_right:
+ exprStr += OString(" >> ");
+ break;
+ }
+
+ if ( m_subExpr2 )
+ exprStr += m_subExpr2->toString();
+
+ return exprStr;
+}
+
+// Convert the type of an AST_Expression to a char *
+sal_Char* SAL_CALL exprTypeToString(ExprType t)
+{
+ switch (t)
+ {
+ case ET_short:
+ return "short";
+ case ET_ushort:
+ return "unsigned short";
+ case ET_long:
+ return "long";
+ case ET_ulong:
+ return "unsigned long";
+ case ET_hyper:
+ return "hyper";
+ case ET_uhyper:
+ return "unsigned hyper";
+ case ET_float:
+ return "float";
+ case ET_double:
+ return "double";
+ case ET_char:
+ return "char";
+ case ET_byte:
+ return "byte";
+ case ET_boolean:
+ return "boolean";
+ case ET_string:
+ return "string";
+ case ET_any:
+ return "any";
+ case ET_type:
+ return "type";
+ case ET_void:
+ return "void";
+ case ET_none:
+ return "none";
+ }
+
+ return ("unkown");
+}
diff --git a/idlc/source/astinterface.cxx b/idlc/source/astinterface.cxx
new file mode 100644
index 000000000000..2215d9cfa110
--- /dev/null
+++ b/idlc/source/astinterface.cxx
@@ -0,0 +1,160 @@
+/*************************************************************************
+ *
+ * $RCSfile: astinterface.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTINTERFACE_HXX_
+#include <idlc/astinterface.hxx>
+#endif
+#ifndef _IDLC_ASTATTRIBUTE_HXX_
+#include <idlc/astattribute.hxx>
+#endif
+#ifndef _IDLC_ASTOPERATION_HXX_
+#include <idlc/astoperation.hxx>
+#endif
+
+using namespace ::rtl;
+
+AstInterface::AstInterface(const ::rtl::OString& name,
+ DeclList* pInherits,
+ sal_Bool bIsDefined,
+ AstScope* pScope)
+ : AstType(NT_interface, name, pScope)
+ , AstScope(NT_interface)
+ , m_bIsDefined(bIsDefined)
+ , m_bForwarded(sal_False)
+ , m_bForwardedInSameFile(sal_False)
+{
+ if ( pInherits )
+ m_inheritedInterfaces = *pInherits;
+}
+
+AstInterface::~AstInterface()
+{
+}
+
+sal_Bool AstInterface::dump(RegistryKey& rKey, RegistryTypeWriterLoader* pLoader)
+{
+ if ( !isDefined() )
+ return sal_True;
+
+ RegistryKey localKey;
+ if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
+ {
+ fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName().getStr(), rKey.getRegistryName().getStr());
+ return sal_False;
+ }
+
+ sal_uInt16 nAttributes = getNodeCount(NT_attribute);
+ sal_uInt16 nMethods = getNodeCount(NT_operation);
+ OUString uBaseTypeName;
+ if ( m_inheritedInterfaces.size() )
+ uBaseTypeName = OStringToOUString(
+ m_inheritedInterfaces.front()->getRelativName(),
+ RTL_TEXTENCODING_UTF8);
+
+ RegistryTypeWriter aBlob(pLoader->getApi(), RT_TYPE_INTERFACE,
+ OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
+ uBaseTypeName, nAttributes, nMethods, 0);
+
+ aBlob.setDoku( getDocumentation() );
+ aBlob.setFileName( OStringToOUString(getFileName(), RTL_TEXTENCODING_UTF8));
+
+ RTUik aUik;
+ aUik.m_Data1 = 0;
+ aUik.m_Data2 = 0;
+ aUik.m_Data3 = 0;
+ aUik.m_Data4 = 0;
+ aUik.m_Data5 = 0;
+ aBlob.setUik(aUik);
+
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+ sal_uInt16 attrIndex = 0;
+ sal_uInt16 methodIndex = 0;
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_attribute )
+ {
+ ((AstAttribute*)pDecl)->dumpBlob(aBlob, attrIndex++);
+ } else
+ if ( pDecl->getNodeType() == NT_operation )
+ {
+ ((AstOperation*)pDecl)->dumpBlob(aBlob, methodIndex++);
+ }
+
+ iter++;
+ }
+
+ const sal_uInt8* pBlob = aBlob.getBlop();
+ sal_uInt32 aBlobSize = aBlob.getBlopSize();
+
+ if (localKey.setValue(OUString(), RG_VALUETYPE_BINARY, (RegValue)pBlob, aBlobSize))
+ {
+ fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName(), localKey.getRegistryName());
+ return sal_False;
+ }
+
+ return AstDeclaration::dump(rKey, pLoader);
+}
diff --git a/idlc/source/astoperation.cxx b/idlc/source/astoperation.cxx
new file mode 100644
index 000000000000..9263cd79c7d9
--- /dev/null
+++ b/idlc/source/astoperation.cxx
@@ -0,0 +1,196 @@
+/*************************************************************************
+ *
+ * $RCSfile: astoperation.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTOPERATION_HXX_
+#include <idlc/astoperation.hxx>
+#endif
+#ifndef _IDLC_ASTTYPE_HXX_
+#include <idlc/asttype.hxx>
+#endif
+#ifndef _IDLC_ASTBASETYPE_HXX_
+#include <idlc/astbasetype.hxx>
+#endif
+#ifndef _IDLC_ASTPARAMETER_HXX_
+#include <idlc/astparameter.hxx>
+#endif
+#ifndef _IDLC_ERRORHANDLER_HXX_
+#include <idlc/errorhandler.hxx>
+#endif
+
+using namespace ::rtl;
+
+void AstOperation::addExceptions(StringList* pExceptions)
+{
+ if ( isOneway() )
+ {
+ idlc()->error()->error1(EIDL_ONEWAY_RAISE_CONFLICT, this);
+ }
+
+ StringList::iterator iter = pExceptions->begin();
+ StringList::iterator end = pExceptions->end();
+ AstDeclaration* pDecl = NULL;
+ while ( iter != end)
+ {
+ pDecl = lookupByName(*iter);
+ if ( !pDecl )
+ {
+ idlc()->error()->lookupError(*iter);
+ return;
+ }
+ if ( (pDecl->getNodeType() == NT_exception) )
+ {
+ m_exceptions.push_back(pDecl);
+ } else
+ {
+ idlc()->error()->error1(EIDL_ILLEGAL_RAISES, this);
+ }
+ iter++;
+ }
+}
+
+sal_Bool AstOperation::isVoid()
+{
+ if ( m_pReturnType && (m_pReturnType->getNodeType() == NT_predefined) )
+ {
+ if ( ((AstBaseType*)m_pReturnType)->getExprType() == ET_void )
+ return sal_True;
+ }
+ return sal_False;
+}
+
+sal_Bool AstOperation::dumpBlob(RegistryTypeWriter& rBlob, sal_uInt16 index)
+{
+ sal_uInt16 nParam = getNodeCount(NT_parameter);
+ sal_uInt16 nExcep = nExceptions();
+ RTMethodMode methodMode = RT_MODE_TWOWAY;
+
+ if ( isOneway() )
+ methodMode = RT_MODE_ONEWAY;
+
+ rBlob.setMethodData(index, OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8),
+ OStringToOUString(getReturnType()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ methodMode, nParam, nExcep, getDocumentation());
+
+ if ( nParam )
+ {
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+ AstParameter* pParam = NULL;
+ RTParamMode paramMode;
+ sal_uInt16 paramIndex = 0;
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_parameter )
+ {
+ AstParameter* pParam = (AstParameter*)pDecl;
+ switch (pParam->getDirection())
+ {
+ case DIR_IN :
+ paramMode = RT_PARAM_IN;
+ break;
+ case DIR_OUT :
+ paramMode = RT_PARAM_OUT;
+ break;
+ case DIR_INOUT :
+ paramMode = RT_PARAM_INOUT;
+ break;
+ }
+
+ rBlob.setParamData(index, paramIndex++,
+ OStringToOUString(pParam->getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ OStringToOUString(pDecl->getLocalName(), RTL_TEXTENCODING_UTF8),
+ paramMode);
+ }
+ iter++;
+ }
+ }
+
+ if ( nExcep )
+ {
+ DeclList::iterator iter = m_exceptions.begin();
+ DeclList::iterator end = m_exceptions.end();
+ sal_uInt16 exceptIndex = 0;
+ while ( iter != end )
+ {
+ rBlob.setExcData(index, exceptIndex++,
+ OStringToOUString((*iter)->getRelativName(), RTL_TEXTENCODING_UTF8) );
+ iter++;
+ }
+ }
+
+ return sal_True;
+}
+
+AstDeclaration* AstOperation::addDeclaration(AstDeclaration* pDecl)
+{
+ if ( pDecl->getNodeType() == NT_parameter )
+ {
+ AstParameter* pParam = (AstParameter*)pDecl;
+ if ( isOneway() &&
+ (pParam->getDirection() == DIR_OUT || pParam->getDirection() == DIR_INOUT) )
+ {
+ idlc()->error()->error2(EIDL_ONEWAY_CONFLICT, pDecl, this);
+ return NULL;
+ }
+ }
+ return AstScope::addDeclaration(pDecl);
+}
diff --git a/idlc/source/astscope.cxx b/idlc/source/astscope.cxx
new file mode 100644
index 000000000000..abc7f112b389
--- /dev/null
+++ b/idlc/source/astscope.cxx
@@ -0,0 +1,385 @@
+/*************************************************************************
+ *
+ * $RCSfile: astscope.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTSCOPE_HXX_
+#include <idlc/astscope.hxx>
+#endif
+#ifndef _IDLC_ASTBASETYPE_HXX_
+#include <idlc/astbasetype.hxx>
+#endif
+#ifndef _IDLC_ASTINERFACE_HXX_
+#include <idlc/astinterface.hxx>
+#endif
+#ifndef _IDLC_ERRORHANDLER_HXX_
+#include <idlc/errorhandler.hxx>
+#endif
+
+
+using namespace ::rtl;
+
+sal_Bool isGlobal(const OString& scopedName)
+{
+ if ((scopedName.getLength() == 0) || (scopedName.indexOf(':') == 0))
+ {
+ return sal_True;
+ }
+ return sal_False;
+}
+
+AstScope::AstScope(NodeType nodeType)
+ : m_nodeType(nodeType)
+{
+
+}
+
+AstScope::~AstScope()
+{
+
+}
+
+AstDeclaration* AstScope::addDeclaration(AstDeclaration* pDecl)
+{
+ AstDeclaration* pDeclaration = NULL;
+
+ if ((pDeclaration = lookupForAdd(pDecl)) != NULL)
+ {
+ if (pDecl->getNodeType() == NT_union_branch )
+ {
+ m_declarations.push_back(pDecl);
+ return pDecl;
+ }
+ if ( pDecl->hasAncestor(pDeclaration) )
+ {
+ idlc()->error()->error2(EIDL_REDEF_SCOPE, pDecl, pDeclaration);
+ return NULL;
+ }
+ if ( (pDecl->getNodeType() == pDeclaration->getNodeType()) &&
+ ((pDecl->getNodeType() == NT_sequence) || (pDeclaration->getNodeType() == NT_array)) )
+ {
+ return pDeclaration;
+ }
+ if ( (pDeclaration->getNodeType() == NT_interface)
+ && (pDecl->getNodeType() == NT_interface)
+ && !((AstInterface*)pDeclaration)->isDefined() )
+ {
+ m_declarations.push_back(pDecl);
+ return pDecl;
+ }
+
+ idlc()->error()->error2(EIDL_REDEF_SCOPE, scopeAsDecl(this), pDecl);
+ return NULL;
+ }
+
+ m_declarations.push_back(pDecl);
+ return pDecl;
+}
+
+sal_uInt16 AstScope::getNodeCount(NodeType nodeType)
+{
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+ sal_uInt16 count = 0;
+
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == nodeType )
+ count++;
+ iter++;
+ }
+ return count;
+}
+
+AstDeclaration* AstScope::lookupByName(const OString& scopedName)
+{
+ AstDeclaration* pDecl = NULL;
+ AstScope* pScope = NULL;
+ if (scopedName.getLength() == 0)
+ return NULL;
+
+ // If name starts with "::" start look up in global scope
+ if ( isGlobal(scopedName) )
+ {
+ pDecl = scopeAsDecl(this);
+ if ( !pDecl )
+ return NULL;
+
+ pScope = pDecl->getScope();
+ // If this is the global scope ...
+ if ( !pScope )
+ {
+ // look up the scopedName part after "::"
+ OString subName = scopedName.copy(2);
+ pDecl = lookupByName(subName);
+ return pDecl;
+ //return pScope->lookupByName();
+ }
+ // OK, not global scope yet, so simply iterate with parent scope
+ pDecl = pScope->lookupByName(scopedName);
+ return pDecl;
+ //return pScope->lookupByName(scopedName);
+ }
+
+ // The name does not start with "::"
+ // Look up in the local scope and start with the first scope
+ OString firstScope = scopedName.indexOf(':') > 0 ?
+ scopedName.getToken(0, ':') : scopedName;
+ sal_Bool bFindFirstScope = sal_True;
+ pDecl = lookupByNameLocal(firstScope);
+ if ( !pDecl )
+ {
+ bFindFirstScope = sal_False;
+
+ // OK, not found. Go down parent scope chain
+ pDecl = scopeAsDecl(this);
+ if ( pDecl )
+ {
+ pScope = pDecl->getScope();
+ if ( pScope )
+ pDecl = pScope->lookupByName(scopedName);
+ else
+ pDecl = NULL;
+
+ // Special case for scope which is an interface. We
+ // have to look in the inherited interfaces as well.
+ if ( !pDecl )
+ {
+ if (m_nodeType == NT_interface)
+ pDecl = lookupInInherited(scopedName);
+ }
+// if ( !pDecl )
+// pDecl = lookupInForwarded(scopedName);
+ }
+ }
+
+ if ( bFindFirstScope && (firstScope != scopedName) )
+ {
+ sal_Int32 count = scopedName.getTokenCount(':');
+ for ( sal_Int32 i = 2; i < count; i += 2 )
+ {
+ pScope = declAsScope(pDecl);
+
+ if ( pScope )
+ pDecl = pScope->lookupByNameLocal(scopedName.getToken(i, ':'));
+
+ if ( !pDecl )
+ return NULL;
+ }
+ }
+
+// if ( !pDecl )
+// pDecl = lookupInForwarded(scopedName);
+
+ return pDecl;
+}
+
+AstDeclaration* AstScope::lookupByNameLocal(const OString& name)
+{
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getLocalName() == name )
+ return pDecl;
+ iter++;
+ }
+ return NULL;
+}
+
+AstDeclaration* AstScope::lookupInInherited(const OString& scopedName)
+{
+ AstDeclaration* pDecl = NULL;
+ AstInterface* pInterface = (AstInterface*)this;
+
+ if ( !pInterface )
+ return NULL;
+
+ // Can't look in an interface which was not yet defined
+ if ( !pInterface->getScope() )
+ {
+ idlc()->error()->forwardLookupError(pInterface, scopedName);
+ }
+
+ // OK, loop through inherited interfaces. Stop when you find it
+ if ( pInterface->nInheritedInterfaces() > 0 )
+ {
+ DeclList::const_iterator iter = pInterface->getInheritedInterfaces().begin();
+ DeclList::const_iterator end = pInterface->getInheritedInterfaces().end();
+
+ while ( iter != end )
+ {
+ pDecl = ((AstInterface*)(*iter))->lookupByName(scopedName);
+ if ( pDecl )
+ return pDecl;;
+ }
+ }
+ // Not found
+ return NULL;
+}
+/*
+AstDeclaration* AstScope::lookupInForwarded(const OString& scopedName)
+{
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_interface_fwd )
+ {
+ if ( pDecl->getScopedName() == scopedName )
+ {
+ AstInterfaceFwd* pFwd = (AstInterfaceFwd*)pDecl;
+ if ( pFwd )
+ return pFwd->getFullDefintion();
+ }
+ break;
+ }
+ iter++;
+ }
+ return NULL;
+}
+*/
+AstDeclaration* AstScope::lookupPrimitiveType(ExprType type)
+{
+ AstDeclaration* pDecl = NULL;
+ AstScope* pScope = NULL;
+ AstBaseType* pBaseType = NULL;
+ OString typeName;
+ pDecl = scopeAsDecl(this);
+ if ( !pDecl )
+ return NULL;
+ pScope = pDecl->getScope();
+ if ( pScope)
+ return pScope->lookupPrimitiveType(type);
+
+ switch (type)
+ {
+ case ET_short:
+ typeName = OString("short");
+ break;
+ case ET_ushort:
+ typeName = OString("unsigned short");
+ break;
+ case ET_long:
+ typeName = OString("long");
+ break;
+ case ET_ulong:
+ typeName = OString("unsigned long");
+ break;
+ case ET_hyper:
+ typeName = OString("hyper");
+ break;
+ case ET_uhyper:
+ typeName = OString("unsigned hyper");
+ break;
+ case ET_float:
+ typeName = OString("float");
+ break;
+ case ET_double:
+ typeName = OString("double");
+ break;
+ case ET_char:
+ typeName = OString("char");
+ break;
+ case ET_byte:
+ typeName = OString("byte");
+ break;
+ case ET_boolean:
+ typeName = OString("boolean");
+ break;
+ case ET_any:
+ typeName = OString("any");
+ break;
+ case ET_void:
+ typeName = OString("void");
+ break;
+ case ET_type:
+ typeName = OString("type");
+ break;
+ case ET_string:
+ typeName = OString("string");
+ break;
+ }
+
+ pDecl = lookupByNameLocal(typeName);
+
+ if ( pDecl && (pDecl->getNodeType() == NT_predefined) )
+ {
+ pBaseType = (AstBaseType*)pDecl;
+
+ if ( pBaseType->getExprType() == type )
+ return pDecl;
+ }
+
+ return NULL;
+}
+
+AstDeclaration* AstScope::lookupForAdd(AstDeclaration* pDecl)
+{
+ if ( !pDecl )
+ return NULL;
+ return lookupByNameLocal(pDecl->getLocalName());
+}
diff --git a/idlc/source/aststack.cxx b/idlc/source/aststack.cxx
new file mode 100644
index 000000000000..96e7abeff32f
--- /dev/null
+++ b/idlc/source/aststack.cxx
@@ -0,0 +1,174 @@
+/*************************************************************************
+ *
+ * $RCSfile: aststack.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _RTL_ALLOC_H_
+#include <rtl/alloc.h>
+#endif
+#ifndef _IDLC_ASTSTACK_HXX_
+#include <idlc/aststack.hxx>
+#endif
+#ifndef _IDLC_ASTSCOPE_HXX_
+#include <idlc/astscope.hxx>
+#endif
+
+#define STACKSIZE_INCREMENT 64
+
+AstStack::AstStack()
+ : m_size(STACKSIZE_INCREMENT)
+ , m_top(0)
+ , m_stack((AstScope**)rtl_allocateZeroMemory(sizeof(AstScope*) * STACKSIZE_INCREMENT))
+{
+}
+
+AstStack::~AstStack()
+{
+ for(sal_uInt32 i=0; i < m_top; i++)
+ {
+ if (m_stack[i])
+ delete(m_stack[i]);
+ }
+
+ rtl_freeMemory(m_stack);
+}
+
+sal_uInt32 AstStack::depth()
+{
+ return m_top;
+}
+
+AstScope* AstStack::top()
+{
+ if (m_top < 1)
+ return NULL;
+ return m_stack[m_top - 1];
+}
+
+AstScope* AstStack::bottom()
+{
+ if (m_top == 0)
+ return NULL;
+ return m_stack[0];
+}
+
+AstScope* AstStack::nextToTop()
+{
+ AstScope *tmp, *retval;
+
+ if (depth() < 2)
+ return NULL;
+
+ tmp = top(); // Save top
+ (void) pop(); // Pop it
+ retval = top(); // Get next one down
+ (void) push(tmp); // Push top back
+ return retval; // Return next one down
+}
+
+AstScope* AstStack::topNonNull()
+{
+ for (sal_uInt32 i = m_top - 1; i >= 0; i--)
+ {
+ if ( m_stack[i] )
+ return m_stack[i];
+ }
+ return NULL;
+}
+
+AstStack* AstStack::push(AstScope* pScope)
+{
+ AstScope **tmp;
+// AstDeclaration *pDecl = ScopeAsDecl(pScope);
+ sal_uInt32 newSize;
+ sal_uInt32 i;
+
+ // Make sure there's space for one more
+ if (m_size == m_top)
+ {
+ newSize = m_size;
+ newSize += STACKSIZE_INCREMENT;
+ tmp = (AstScope**)rtl_allocateZeroMemory(sizeof(AstScope*) * newSize);
+
+ for(i=0; i < m_size; i++)
+ tmp[i] = m_stack[i];
+
+ rtl_freeMemory(m_stack);
+ m_stack = tmp;
+ }
+
+ // Insert new scope
+ m_stack[m_top++] = pScope;
+
+ return this;
+}
+
+void AstStack::pop()
+{
+ AstScope *pScope;
+
+ if (m_top < 1)
+ return;
+ pScope = m_stack[--m_top];
+}
+
+void AstStack::clear()
+{
+ m_top = 0;
+}
+
diff --git a/idlc/source/aststruct.cxx b/idlc/source/aststruct.cxx
new file mode 100644
index 000000000000..10dcfa9fc97d
--- /dev/null
+++ b/idlc/source/aststruct.cxx
@@ -0,0 +1,156 @@
+/*************************************************************************
+ *
+ * $RCSfile: aststruct.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTSTRUCT_HXX_
+#include <idlc/aststruct.hxx>
+#endif
+#ifndef _IDLC_ASTMember_HXX_
+#include <idlc/astmember.hxx>
+#endif
+
+using namespace ::rtl;
+
+AstStruct::AstStruct(const OString& name, AstStruct* pBaseType, AstScope* pScope)
+ : AstType(NT_struct, name, pScope)
+ , AstScope(NT_struct)
+ , m_pBaseType(pBaseType)
+{
+}
+
+AstStruct::AstStruct(const NodeType type,
+ const OString& name,
+ AstStruct* pBaseType,
+ AstScope* pScope)
+ : AstType(type, name, pScope)
+ , AstScope(type)
+ , m_pBaseType(pBaseType)
+{
+}
+
+AstStruct::~AstStruct()
+{
+}
+
+sal_Bool AstStruct::dump(RegistryKey& rKey, RegistryTypeWriterLoader* pLoader)
+{
+ RegistryKey localKey;
+ if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
+ {
+ fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName().getStr(), rKey.getRegistryName().getStr());
+ return sal_False;
+ }
+
+ sal_uInt16 nMember = getNodeCount(NT_member);
+ OUString uBaseTypeName;
+ if ( m_pBaseType )
+ uBaseTypeName = OStringToOUString(m_pBaseType->getRelativName(),
+ RTL_TEXTENCODING_UTF8);
+
+ RTTypeClass typeClass = RT_TYPE_STRUCT;
+ if ( getNodeType() == NT_exception )
+ typeClass = RT_TYPE_EXCEPTION;
+
+ RegistryTypeWriter aBlob(pLoader->getApi(), typeClass,
+ OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
+ uBaseTypeName, nMember, 0, 0);
+
+ aBlob.setDoku( getDocumentation() );
+ aBlob.setFileName( OStringToOUString(getFileName(), RTL_TEXTENCODING_UTF8));
+
+ if ( nMember > 0 )
+ {
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+ AstMember* pMember = NULL;
+ OUString docu;
+ sal_uInt16 index = 0;
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_member )
+ {
+ pMember = (AstMember*)pDecl;
+ aBlob.setFieldData(index++,
+ OStringToOUString(pMember->getLocalName(), RTL_TEXTENCODING_UTF8),
+ OStringToOUString(pMember->getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ pMember->getDocumentation(), OUString(), RT_ACCESS_READWRITE);
+ }
+ iter++;
+ }
+ }
+
+ const sal_uInt8* pBlob = aBlob.getBlop();
+ sal_uInt32 aBlobSize = aBlob.getBlopSize();
+
+ if (localKey.setValue(OUString(), RG_VALUETYPE_BINARY,
+ (RegValue)pBlob, aBlobSize))
+ {
+ fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName(), localKey.getRegistryName());
+ return sal_False;
+ }
+
+ return sal_True;
+}
+
diff --git a/idlc/source/astunion.cxx b/idlc/source/astunion.cxx
new file mode 100644
index 000000000000..71286353d20a
--- /dev/null
+++ b/idlc/source/astunion.cxx
@@ -0,0 +1,430 @@
+/*************************************************************************
+ *
+ * $RCSfile: astunion.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ASTUNION_HXX_
+#include <idlc/astunion.hxx>
+#endif
+#ifndef _IDLC_ASTBASETYPE_HXX_
+#include <idlc/astbasetype.hxx>
+#endif
+#ifndef _IDLC_ERRORHANDLER_HXX_
+#include <idlc/errorhandler.hxx>
+#endif
+
+using namespace ::rtl;
+
+AstUnion::AstUnion(const ::rtl::OString& name, AstType* pDiscType, AstScope* pScope)
+ : AstStruct(NT_union, name, NULL, pScope)
+ , m_pDiscriminantType(pDiscType)
+ , m_discExprType(ET_long)
+{
+ AstBaseType* pBaseType;
+
+ if ( !pDiscType )
+ {
+ m_pDiscriminantType = NULL;
+ m_discExprType = ET_none;
+ return;
+ }
+ /*
+ * If the discriminator type is a predefined type
+ * then install the equivalent coercion target type in
+ * the pd_udisc_type field.
+ */
+ if ( pDiscType->getNodeType() == NT_predefined )
+ {
+ pBaseType = (AstBaseType*)pDiscType;
+ if ( !pBaseType )
+ {
+ m_pDiscriminantType = NULL;
+ m_discExprType = ET_none;
+ return;
+ }
+ m_pDiscriminantType = pDiscType;
+ switch (pBaseType->getExprType())
+ {
+ case ET_long:
+ case ET_ulong:
+ case ET_short:
+ case ET_ushort:
+ case ET_char:
+ case ET_boolean:
+ m_discExprType = pBaseType->getExprType();
+ break;
+ default:
+ m_discExprType = ET_none;
+ m_pDiscriminantType = NULL;
+ break;
+ }
+ } else
+ if (pDiscType->getNodeType() == NT_enum)
+ {
+ m_discExprType = ET_any;
+ m_pDiscriminantType = pDiscType;
+ } else
+ {
+ m_discExprType = ET_none;
+ m_pDiscriminantType = NULL;
+ }
+
+ if ( !m_pDiscriminantType )
+ idlc()->error()->error2(EIDL_DISC_TYPE, this, pDiscType);
+}
+
+AstUnion::~AstUnion()
+{
+}
+
+AstDeclaration* AstUnion::addDeclaration(AstDeclaration* pDecl)
+{
+ if ( pDecl->getNodeType() == NT_union_branch )
+ {
+ AstUnionBranch* pBranch = (AstUnionBranch*)pDecl;
+ if ( lookupBranch(pBranch) )
+ {
+ idlc()->error()->error2(EIDL_MULTIPLE_BRANCH, this, pDecl);
+ return NULL;
+ }
+ }
+
+ return AstScope::addDeclaration(pDecl);
+}
+
+AstUnionBranch* AstUnion::lookupBranch(AstUnionBranch* pBranch)
+{
+ AstUnionLabel* pLabel = NULL;
+
+ if ( pBranch )
+ pLabel = pBranch->getLabel();
+
+ if ( pLabel )
+ {
+ if (pLabel->getLabelKind() == UL_default)
+ return lookupDefault();
+ if (m_discExprType == ET_any)
+ /* CONVENTION: indicates enum discr */
+ return lookupEnum(pBranch);
+ return lookupLabel(pBranch);
+ }
+ return NULL;
+}
+
+AstUnionBranch* AstUnion::lookupDefault(sal_Bool bReportError)
+{
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstUnionBranch *pBranch = NULL;
+ AstDeclaration *pDecl = NULL;
+
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_union_branch )
+ {
+ pBranch = (AstUnionBranch*)pDecl;
+ if (pBranch == NULL)
+ {
+ iter++;
+ continue;
+ }
+ if ( pBranch->getLabel() != NULL &&
+ pBranch->getLabel()->getLabelKind() == UL_default)
+ {
+ if ( bReportError )
+ idlc()->error()->error2(EIDL_MULTIPLE_BRANCH, this, pBranch);
+ return pBranch;
+ }
+ }
+ iter++;
+ }
+ return NULL;
+}
+
+AstUnionBranch* AstUnion::lookupLabel(AstUnionBranch* pBranch)
+{
+ AstUnionLabel* pLabel = pBranch->getLabel();
+
+ if ( !pLabel->getLabelValue() )
+ return pBranch;
+// pLabel->getLabelValue()->setExprValue(pLabel->getLabelValue()->coerce(m_discExprType, sal_False));
+ AstExprValue* pLabelValue = NULL;
+ if ( !(pLabelValue = pLabel->getLabelValue()->coerce(m_discExprType, sal_False)) )
+ {
+ idlc()->error()->evalError(pLabel->getLabelValue());
+ return pBranch;
+ } else
+ {
+ pLabel->getLabelValue()->setExprValue(pLabelValue);
+ }
+
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstUnionBranch* pB = NULL;
+ AstDeclaration* pDecl = NULL;
+
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_union_branch )
+ {
+ pB = (AstUnionBranch*)pDecl;
+ if ( !pB )
+ {
+ iter++;
+ continue;
+ }
+ if ( pB->getLabel() != NULL &&
+ pB->getLabel()->getLabelKind() == UL_label &&
+ pB->getLabel()->getLabelValue()->compare(pLabel->getLabelValue()) )
+ {
+ idlc()->error()->error2(EIDL_MULTIPLE_BRANCH, this, pBranch);
+ return pBranch;
+ }
+ }
+ iter++;
+ }
+ return NULL;
+}
+
+AstUnionBranch* AstUnion::lookupEnum(AstUnionBranch* pBranch)
+{
+ AstType* pType = resolveTypeDef(m_pDiscriminantType);
+ if ( pType->getNodeType() != NT_enum )
+ return NULL;
+
+ AstUnionLabel* pLabel = pBranch->getLabel();
+ AstExpression* pExpr = pLabel->getLabelValue();
+ if ( !pExpr )
+ return pBranch;
+
+ /*
+ * Expecting a symbol label
+ */
+ if ( pExpr->getCombOperator() != EC_symbol)
+ {
+ idlc()->error()->enumValExpected(this, pLabel);
+ return pBranch;
+ }
+
+ /*
+ * See if the symbol defines a constant in the discriminator enum
+ */
+ AstEnum* pEnum = (AstEnum*)pType;
+ AstDeclaration* pDecl = pEnum->lookupByName(*pExpr->getSymbolicName());
+ if ( pDecl == NULL || pDecl->getScope() != pEnum)
+ {
+ idlc()->error()->enumValLookupFailure(this, pEnum, *pExpr->getSymbolicName());
+ return pBranch;
+ }
+
+
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstUnionBranch* pB = NULL;
+ pDecl = NULL;
+
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_union_branch )
+ {
+ pB = (AstUnionBranch*)pDecl;
+ if ( !pB )
+ {
+ iter++;
+ continue;
+ }
+ if ( pB->getLabel() != NULL &&
+ pB->getLabel()->getLabelKind() == UL_label &&
+ pB->getLabel()->getLabelValue()->compare(pLabel->getLabelValue()) )
+ {
+ idlc()->error()->error2(EIDL_MULTIPLE_BRANCH, this, pBranch);
+ return pBranch;
+ }
+ }
+ iter++;
+ }
+ return NULL;
+}
+
+sal_Bool AstUnion::dump(RegistryKey& rKey, RegistryTypeWriterLoader* pLoader)
+{
+ RegistryKey localKey;
+ if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
+ {
+ fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName().getStr(), rKey.getRegistryName().getStr());
+ return sal_False;
+ }
+
+ sal_uInt16 nMember = getNodeCount(NT_union_branch);
+
+ RegistryTypeWriter aBlob(pLoader->getApi(), RT_TYPE_UNION,
+ OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
+ OStringToOUString(getDiscrimantType()->getScopedName(), RTL_TEXTENCODING_UTF8),
+ nMember, 0, 0);
+
+ aBlob.setDoku( getDocumentation() );
+ aBlob.setFileName( OStringToOUString(getFileName(), RTL_TEXTENCODING_UTF8));
+
+ if ( nMember > 0 )
+ {
+ DeclList::iterator iter = getIteratorBegin();
+ DeclList::iterator end = getIteratorEnd();
+ AstDeclaration* pDecl = NULL;
+ AstUnionBranch* pBranch = NULL;
+ AstUnionBranch* pDefault = lookupDefault(sal_False);
+ AstUnionLabel* pLabel = NULL;
+ AstExprValue* pExprValue = NULL;
+ RTConstValue aConst;
+ RTFieldAccess access = RT_ACCESS_READWRITE;
+ OUString docu;
+ sal_uInt16 index = 0;
+ if ( pDefault )
+ index = 1;
+
+ sal_Int64 disc = 0;
+ while ( iter != end )
+ {
+ pDecl = *iter;
+ if ( pDecl->getNodeType() == NT_union_branch )
+ {
+ pBranch = (AstUnionBranch*)pDecl;
+ if (pBranch == pDefault)
+ {
+ iter++;
+ continue;
+ }
+
+ pLabel = pBranch->getLabel();
+ pExprValue = pLabel->getLabelValue()->coerce(ET_hyper, sal_False);
+ aConst.m_type = RT_TYPE_INT64;
+ aConst.m_value.aHyper = pExprValue->u.hval;
+ if ( aConst.m_value.aHyper > disc )
+ disc = aConst.m_value.aHyper;
+
+ aBlob.setFieldData(index++,
+ OStringToOUString(pBranch->getLocalName(), RTL_TEXTENCODING_UTF8),
+ OStringToOUString(pBranch->getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ pBranch->getDocumentation(), OUString(), RT_ACCESS_READWRITE, aConst);
+ }
+ iter++;
+ }
+
+ if ( pDefault )
+ {
+ access = RT_ACCESS_DEFAULT;
+ aConst.m_type = RT_TYPE_INT64;
+ aConst.m_value.aHyper = disc + 1;
+ aBlob.setFieldData(0,
+ OStringToOUString(pDefault->getLocalName(), RTL_TEXTENCODING_UTF8),
+ OStringToOUString(pDefault->getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
+ pDefault->getDocumentation(), OUString(), RT_ACCESS_DEFAULT, aConst);
+ }
+ }
+
+ const sal_uInt8* pBlob = aBlob.getBlop();
+ sal_uInt32 aBlobSize = aBlob.getBlopSize();
+
+ if (localKey.setValue(OUString(), RG_VALUETYPE_BINARY,
+ (RegValue)pBlob, aBlobSize))
+ {
+ fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ getFullName(), localKey.getRegistryName());
+ return sal_False;
+ }
+
+ return sal_True;
+}
+
+AstUnionBranch::AstUnionBranch(AstUnionLabel* pLabel, AstType* pType, const ::rtl::OString& name, AstScope* pScope)
+ : AstMember(NT_union_branch, pType, name, pScope)
+ , m_pLabel(pLabel)
+{
+}
+
+AstUnionBranch::~AstUnionBranch()
+{
+ if ( m_pLabel )
+ delete m_pLabel;
+}
+
+AstUnionLabel::AstUnionLabel()
+ : m_label(UL_default)
+ , m_pLabelValue(NULL)
+{
+}
+
+AstUnionLabel::AstUnionLabel(UnionLabel labelKind, AstExpression* pExpr)
+ : m_label(labelKind)
+ , m_pLabelValue(pExpr)
+{
+ if ( m_pLabelValue )
+ m_pLabelValue->evaluate(EK_const);
+}
+
+AstUnionLabel::~AstUnionLabel()
+{
+ if ( m_pLabelValue )
+ delete m_pLabelValue;
+}
+
diff --git a/idlc/source/errorhandler.cxx b/idlc/source/errorhandler.cxx
new file mode 100644
index 000000000000..756e31a1fbf8
--- /dev/null
+++ b/idlc/source/errorhandler.cxx
@@ -0,0 +1,653 @@
+/*************************************************************************
+ *
+ * $RCSfile: errorhandler.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_ERRORHANDLER_HXX_
+#include <idlc/errorhandler.hxx>
+#endif
+#ifndef _IDLC_ASTINTERFACE_HXX_
+#include <idlc/astinterface.hxx>
+#endif
+
+using namespace ::rtl;
+
+static sal_Char* errorCodeToMessage(ErrorCode eCode)
+{
+ switch (eCode)
+ {
+ case EIDL_NONE:
+ return "all is fine ";
+ case EIDL_SYNTAX_ERROR:
+ return "";
+ case EIDL_REDEF:
+ return "illegal redefinition ";
+ case EIDL_REDEF_SCOPE:
+ return "illegal redefinition in scope ";
+ case EIDL_DEF_USE:
+ return "redefinition after use, ";
+ case EIDL_MULTIPLE_BRANCH:
+ return "union with duplicate branch label ";
+ case EIDL_COERCION_FAILURE:
+ return "coercion failure ";
+ case EIDL_SCOPE_CONFLICT:
+ return "definition scope is different than fwd declare scope, ";
+ case EIDL_ONEWAY_CONFLICT:
+ return "oneway operation with OUT|INOUT parameters or raises exceptions, ";
+ case EIDL_DISC_TYPE:
+ return "union with illegal discriminator type, ";
+ case EIDL_LABEL_TYPE:
+ return "label type incompatible with union discriminator type, ";
+ case EIDL_ILLEGAL_ADD:
+ return "illegal add operation, ";
+ case EIDL_ILLEGAL_USE:
+ return "illegal type used in expression, ";
+ case EIDL_ILLEGAL_RAISES:
+ return "error in raises(..) clause, ";
+ case EIDL_CANT_INHERIT:
+ return "cannot inherit from ";
+ case EIDL_LOOKUP_ERROR:
+ return "error in lookup of symbol: ";
+ case EIDL_INHERIT_FWD_ERROR:
+ return "";
+ case EIDL_CONSTANT_EXPECTED:
+ return "constant expected: ";
+ case EIDL_NAME_CASE_ERROR:
+ return "identifier used with two differing spellings: ";
+ case EIDL_ENUM_VAL_EXPECTED:
+ return "enumerator expected: ";
+ case EIDL_ENUM_VAL_NOT_FOUND:
+ return "enumerator by this name not defined: ";
+ case EIDL_EVAL_ERROR:
+ return "expression evaluation error: ";
+ case EIDL_AMBIGUOUS:
+ return "ambiguous definition: ";
+ case EIDL_DECL_NOT_DEFINED:
+ return "forward declared but never defined: ";
+ case EIDL_FWD_DECL_LOOKUP:
+ return "";
+ case EIDL_RECURSIVE_TYPE:
+ return "illegal recursive use of type: ";
+ case EIDL_NONVOID_ONEWAY:
+ return "non-void return type in oneway operation: ";
+ case EIDL_NOT_A_TYPE:
+ return "specified symbol is not a type: ";
+ case EIDL_TYPE_NOT_VALID:
+ return "specified type is not valid in this context: ";
+ case EIDL_INTERFACEMEMBER_LOOKUP:
+ return "error in lookup of symbol, expected interface is not defined and no forward exists: ";
+ case EIDL_SERVICEMEMBER_LOOKUP:
+ return "error in lookup of symbol, expected service is not defined: ";
+ case EIDL_MULTIBLE_INHERITANCE:
+ return "multible inheritance is not allowed, in inheritance tree: ";
+ case EIDL_TYPE_IDENT_CONFLICT:
+ return "type and parameter/member name are equal: ";
+ case EIDL_ONEWAY_RAISE_CONFLICT:
+ return "oneway operation cannot raises exceptions: ";
+ case EIDL_WRONGATTRIBUTEFLAG:
+ return "the used flag is not valid in this context: ";
+ case EIDL_DEFINED_ATTRIBUTEFLAG:
+ return "flag is already set: ";
+ case EIDL_WRONGATTRIBUTEKEYWORD:
+ return "keyword not allowed: ";
+ case EIDL_MISSINGATTRIBUTEKEYWORD:
+ return "missing keyword: ";
+ case EIDL_ATTRIBUTEREADONLYEXPECTED:
+ return "only the 'attribute'|'readonly' flag is accepted: ";
+ case EIDL_OPTIONALEXPECTED:
+ return "only the 'optional' flag is accepted: ";
+ }
+ return "unknown errror";
+}
+
+static sal_Char* warningCodeToMessage(WarningCode wCode)
+{
+ switch (wCode)
+ {
+ case WIDL_EXPID_CONFLICT:
+ return "exception id conflict: ";
+ case WIDL_REQID_CONFLICT:
+ return "request id conflict: ";
+ case WIDL_INHERIT_IDCONFLICT:
+ return "request id conflict in inheritance tree: ";
+ case WIDL_TYPE_IDENT_CONFLICT:
+ return "type and parameter|member name are equal: ";
+ }
+ return "unkown warning";
+}
+
+static sal_Char* parseStateToMessage(ParseState state)
+{
+ switch (state)
+ {
+ case PS_NoState:
+ return "Statement can not be parsed";
+ case PS_TypeDeclSeen:
+ return "Malformed type declaration";
+ case PS_ConstantDeclSeen:
+ return "Malformed const declaration";
+ case PS_ExceptionDeclSeen:
+ return "Malformed exception declaration";
+ case PS_InterfaceDeclSeen:
+ return "Malformed interface declaration";
+ case PS_ServiceDeclSeen:
+ return "Malformed servicve declaration";
+ case PS_ModuleDeclSeen:
+ return "Malformed module declaration";
+ case PS_AttributeDeclSeen:
+ return "Malformed attribute declaration";
+ case PS_PropertyDeclSeen:
+ return "Malformed property declaration";
+ case PS_OperationDeclSeen:
+ return "Malformed operation declaration";
+ case PS_ConstantsDeclSeen:
+ return "Malformed constants declaration";
+ case PS_ServiceSeen:
+ return "Missing service identifier following SERVICE keyword";
+ case PS_ServiceIDSeen:
+ return "Missing '{' or illegal syntax following service identifier";
+ case PS_ServiceSqSeen:
+ return "Illegal syntax following service '{' opener";
+ case PS_ServiceBodySeen:
+ return "Illegal syntax following service '}' closer";
+ case PS_ServiceMemberSeen:
+ return "Illegal syntax following service member declaration";
+ case PS_ServiceIFHeadSeen:
+ return "Illegal syntax following header of an interface member";
+ case PS_ServiceSHeadSeen:
+ return "Illegal syntax following header of an service member";
+ case PS_ModuleSeen:
+ return "Missing module identifier following MODULE keyword";
+ case PS_ModuleIDSeen:
+ return "Missing '{' or illegal syntax following module identifier";
+ case PS_ModuleSqSeen:
+ return "Illegal syntax following module '{' opener";
+ case PS_ModuleQsSeen:
+ return "Illegal syntax following module '}' closer";
+ case PS_ModuleBodySeen:
+ return "Illegal syntax following module export(s)";
+ case PS_ConstantsSeen:
+ return "Missing constants identifier following CONSTANTS keyword";
+ case PS_ConstantsIDSeen:
+ return "Missing '{' or illegal syntax following constants identifier";
+ case PS_ConstantsSqSeen:
+ return "Illegal syntax following module '{' opener";
+ case PS_ConstantsQsSeen:
+ return "Illegal syntax following module '}' closer";
+ case PS_ConstantsBodySeen:
+ return "Illegal syntax following constants export(s)";
+ case PS_InterfaceSeen:
+ return "Missing interface identifier following INTERFACE keyword";
+ case PS_InterfaceIDSeen:
+ return "Illegal syntax following interface identifier";
+ case PS_InterfaceHeadSeen:
+ return "Illegal syntax following interface head";
+ case PS_InheritSpecSeen:
+ return "Missing '{' or illegal syntax following inheritance spec";
+ case PS_ForwardDeclSeen:
+ return "Missing ';' following forward interface declaration";
+ case PS_InterfaceSqSeen:
+ return "Illegal syntax following interface '{' opener";
+ case PS_InterfaceQsSeen:
+ return "Illegal syntax following interface '}' closer";
+ case PS_InterfaceBodySeen:
+ return "Illegal syntax following interface export(s)";
+ case PS_InheritColonSeen:
+ return "Illegal syntax following ':' starting inheritance list";
+ case PS_SNListCommaSeen:
+ return "Found illegal scoped name in scoped name list";
+ case PS_ScopedNameSeen:
+ return "Missing ',' following scoped name in scoped name list";
+ case PS_SN_IDSeen:
+ return "Illegal component in scoped name";
+ case PS_ScopeDelimSeen:
+ return "Illegal component in scoped name following '::'";
+ case PS_ConstSeen:
+ return "Missing type or illegal syntax following CONST keyword";
+ case PS_ConstTypeSeen:
+ return "Missing identifier or illegal syntax following const type";
+ case PS_ConstIDSeen:
+ return "Missing '=' or illegal syntax after const identifier";
+ case PS_ConstAssignSeen:
+ return "Missing value expr or illegal syntax following '='";
+ case PS_ConstExprSeen:
+ return "Missing ';' or illegal syntax following value expr in const";
+ case PS_TypedefSeen:
+ return "Missing type or illegal syntax following TYPEDEF keyword";
+ case PS_TypeSpecSeen:
+ return "Missing declarators or illegal syntax following type spec";
+ case PS_DeclaratorsSeen:
+ return "Illegal syntax following declarators in TYPEDEF declaration";
+ case PS_StructSeen:
+ return "Missing struct identifier following STRUCT keyword";
+ case PS_StructHeaderSeen:
+ return "Missing '{' or illegal syntax following struct inheritance spec";
+ case PS_StructIDSeen:
+ return "Missing '{' or illegal syntax following struct identifier";
+ case PS_StructSqSeen:
+ return "Illegal syntax following struct '{' opener";
+ case PS_StructQsSeen:
+ return "Illegal syntax following struct '}' closer";
+ case PS_StructBodySeen:
+ return "Illegal syntax following struct member(s)";
+ case PS_MemberTypeSeen:
+ return "Illegal syntax or missing identifier following member type";
+ case PS_MemberDeclsSeen:
+ return "Illegal syntax following member declarator(s)";
+ case PS_MemberDeclsCompleted:
+ return "Missing ',' between member decls of same type(?)";
+ case PS_UnionSeen:
+ return "Missing identifier following UNION keyword";
+ case PS_UnionIDSeen:
+ return "Illegal syntax following union identifier";
+ case PS_SwitchSeen:
+ return "Illegal syntax following SWITCH keyword";
+ case PS_SwitchOpenParSeen:
+ return "Illegal syntax following '(' in switch in union";
+ case PS_SwitchTypeSeen:
+ return "Illegal syntax following type decl in switch in union";
+ case PS_SwitchCloseParSeen:
+ return "Missing union '{' opener";
+ case PS_UnionSqSeen:
+ return "Illegal syntax following union '{' opener";
+ case PS_UnionQsSeen:
+ return "Illegal syntax following union '}' closer";
+ case PS_DefaultSeen:
+ return "Illegal syntax or missing ':' following DEFAULT keyword";
+ case PS_UnionLabelSeen:
+ return "Illegal syntax following branch label in union";
+ case PS_LabelColonSeen:
+ return "Illegal syntax following ':' in branch label in union";
+ case PS_LabelExprSeen:
+ return "Illegal syntax following label expression in union";
+ case PS_UnionElemSeen:
+ case PS_UnionElemCompleted:
+ return "Illegal syntax following union element";
+ case PS_CaseSeen:
+ return "Illegal syntax following CASE keyword in union";
+ case PS_UnionElemTypeSeen:
+ return "Illegal syntax following type decl in union element";
+ case PS_UnionElemDeclSeen:
+ return "Illegal syntax following declarator in union element";
+ case PS_UnionBodySeen:
+ return "Illegal syntax following union body statement(s)";
+ case PS_EnumSeen:
+ return "Illegal syntax or missing identifier following ENUM keyword";
+ case PS_EnumIDSeen:
+ return "Illegal syntax or missing '{' following enum identifier";
+ case PS_EnumSqSeen:
+ return "Illegal syntax following enum '{' opener";
+ case PS_EnumQsSeen:
+ return "Illegal syntax following enum '}' closer";
+ case PS_EnumBodySeen:
+ return "Illegal syntax following enum enumerator(s)";
+ case PS_EnumCommaSeen:
+ return "Illegal syntax or missing identifier following ',' in enum";
+ case PS_SequenceSeen:
+ return "Illegal syntax or missing '<' following SEQUENCE keyword";
+ case PS_SequenceSqSeen:
+ return "Illegal syntax or missing type following '<' in sequence";
+ case PS_SequenceQsSeen:
+ return "Illegal syntax following '>' in sequence";
+ case PS_SequenceTypeSeen:
+ return "Illegal syntax following sequence type declaration";
+ case PS_ArrayIDSeen:
+ return "Illegal syntax or missing dimensions after array identifier";
+ case PS_ArrayCompleted:
+ return "Illegal syntax after array declaration";
+ case PS_DimSqSeen:
+ return "Illegal syntax or missing size expr after '[' in array declaration";
+ case PS_DimQsSeen:
+ return "Illegal syntax after ']' in array declaration";
+ case PS_DimExprSeen:
+ return "Illegal syntax or missing ']' after size expr in array declaration";
+ case PS_FlagHeaderSeen:
+ return "Illegal syntax after flags";
+ case PS_AttrSeen:
+ return "Illegal syntax after ATTRIBUTE keyword";
+ case PS_AttrTypeSeen:
+ return "Illegal syntax after type in attribute declaration";
+ case PS_AttrCompleted:
+ return "Illegal syntax after attribute declaration";
+ case PS_ReadOnlySeen:
+ return "Illegal syntax after READONLY keyword";
+ case PS_OptionalSeen:
+ return "Illegal syntax after OPTIONAL keyword";
+ case PS_MayBeVoidSeen:
+ return "Illegal syntax after MAYBEVOID keyword";
+ case PS_BoundSeen:
+ return "Illegal syntax after BOUND keyword";
+ case PS_ConstrainedSeen:
+ return "Illegal syntax after CONSTRAINED keyword";
+ case PS_TransientSeen:
+ return "Illegal syntax after TRANSIENT keyword";
+ case PS_MayBeAmbigiousSeen:
+ return "Illegal syntax after MAYBEAMBIGIOUS keyword";
+ case PS_MayBeDefaultSeen:
+ return "Illegal syntax after MAYBEDEFAULT keyword";
+ case PS_RemoveableSeen:
+ return "Illegal syntax after REMOVEABLE keyword";
+ case PS_PropertySeen:
+ return "Illegal syntax after PROPERTY keyword";
+ case PS_PropertyTypeSeen:
+ return "Illegal syntax after type in property declaration";
+ case PS_PropertyCompleted:
+ return "Illegal syntax after property declaration";
+ case PS_ExceptSeen:
+ return "Illegal syntax or missing identifier after EXCEPTION keyword";
+ case PS_ExceptHeaderSeen:
+ return "Missing '{' or illegal syntax following exception inheritance spec";
+ case PS_ExceptIDSeen:
+ return "Illegal syntax or missing '{' after exception identifier";
+ case PS_ExceptSqSeen:
+ return "Illegal syntax after exception '{' opener";
+ case PS_ExceptQsSeen:
+ return "Illegal syntax after exception '}' closer";
+ case PS_ExceptBodySeen:
+ return "Illegal syntax after exception member(s)";
+ case PS_OpHeadSeen:
+ return "Illegasl syntax after operation header";
+ case PS_OpTypeSeen:
+ return "Illegal syntax or missing identifier after operation type";
+ case PS_OpIDSeen:
+ return "Illegal syntax or missing '(' after operation identifier";
+ case PS_OpParsCompleted:
+ return "Illegal syntax after operation parameter list";
+ case PS_OpRaiseCompleted:
+ return "Illegal syntax after optional RAISES in operation declaration";
+ case PS_OpCompleted:
+ return "Illegal syntax after operation declaration";
+ case PS_OpSqSeen:
+ return "Illegal syntax after operation parameter list '(' opener";
+ case PS_OpQsSeen:
+ return "Illegal syntax after operation parameter list ')' closer";
+ case PS_OpParCommaSeen:
+ return "Illegal syntax or missing direction in parameter declaration";
+ case PS_OpParDirSeen:
+ return "Illegal syntax or missing type in parameter declaration";
+ case PS_OpParTypeSeen:
+ return "Illegal syntax or missing declarator in parameter declaration";
+ case PS_OpParDeclSeen:
+ return "Illegal syntax following parameter declarator";
+ case PS_OpRaiseSeen:
+ return "Illegal syntax or missing '(' after RAISES keyword";
+ case PS_OpRaiseSqSeen:
+ return "Illegal syntax after RAISES '(' opener";
+ case PS_OpRaiseQsSeen:
+ return "Illegal syntax after RAISES ')' closer";
+ case PS_OpOnewaySeen:
+ return "Illegal syntax after ONEWAY keyword";
+ case PS_DeclsCommaSeen:
+ return "Illegal syntax after ',' in declarators list";
+ case PS_DeclsDeclSeen:
+ return "Illegal syntax after declarator in declarators list";
+ }
+ return "no wider described syntax error";
+}
+
+static OString flagToString(sal_uInt32 flag)
+{
+ OString flagStr;
+ if ( (flag & AF_READONLY) == AF_READONLY )
+ flagStr += "'readonly'";
+ if ( (flag & AF_OPTIONAL) == AF_OPTIONAL )
+ flagStr += "'optional'";
+ if ( (flag & AF_MAYBEVOID) == AF_MAYBEVOID )
+ flagStr += "'maybevoid'";
+ if ( (flag & AF_BOUND) == AF_BOUND )
+ flagStr += "'bound'";
+ if ( (flag & AF_CONSTRAINED) == AF_CONSTRAINED )
+ flagStr += "'constrained'";
+ if ( (flag & AF_TRANSIENT) == AF_TRANSIENT )
+ flagStr += "'transient'";
+ if ( (flag & AF_MAYBEAMBIGUOUS) == AF_MAYBEAMBIGUOUS )
+ flagStr += "'maybeambiguous'";
+ if ( (flag & AF_MAYBEDEFAULT) == AF_MAYBEDEFAULT )
+ flagStr += "'maybedefault'";
+ if ( (flag & AF_REMOVEABLE) == AF_REMOVEABLE )
+ flagStr += "'removeable'";
+ if ( (flag & AF_ATTRIBUTE) == AF_ATTRIBUTE )
+ flagStr += "'attribute'";
+ if ( (flag & AF_PROPERTY) == AF_PROPERTY )
+ flagStr += "'property'";
+ if ( !flagStr.getLength() )
+ flagStr += "'unknown'";
+
+ return flagStr;
+}
+
+static void errorHeader(ErrorCode eCode, sal_Int32 lineNumber)
+{
+ OString file;
+ if ( idlc()->getFileName() == idlc()->getRealFileName() )
+ file = idlc()->getMainFileName();
+ else
+ file = idlc()->getFileName();
+
+ fprintf(stderr, "%s(%d) : %s", file.getStr(), lineNumber,
+ errorCodeToMessage(eCode));
+}
+
+static void errorHeader(ErrorCode eCode)
+{
+ errorHeader(eCode, idlc()->getLineNumber());
+}
+
+static void warningHeader(WarningCode wCode)
+{
+ OString file;
+ if ( idlc()->getFileName() == idlc()->getRealFileName() )
+ file = idlc()->getMainFileName();
+ else
+ file = idlc()->getFileName();
+
+ fprintf(stderr, "%s(%d) : WARNING, %s", file.getStr(), idlc()->getLineNumber(),
+ warningCodeToMessage(wCode));
+}
+
+void ErrorHandler::error0(ErrorCode e)
+{
+ errorHeader(e);
+ fprintf(stderr, "\n");
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::error1(ErrorCode e, AstDeclaration* d)
+{
+ errorHeader(e);
+ fprintf(stderr, "'%s'\n", d->getScopedName().getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::error2(ErrorCode e, AstDeclaration* d1, AstDeclaration* d2)
+{
+ errorHeader(e);
+ fprintf(stderr, "'%s', '%s'\n", d1->getScopedName().getStr(),
+ d2->getScopedName().getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::error3(ErrorCode e, AstDeclaration* d1, AstDeclaration* d2, AstDeclaration* d3)
+{
+ errorHeader(e);
+ fprintf(stderr, "'%s', '%s', '%s'\n", d1->getScopedName().getStr(),
+ d2->getScopedName().getStr(), d3->getScopedName().getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::warning1(WarningCode w, AstDeclaration* d)
+{
+ warningHeader(w);
+ fprintf(stderr, "'%s'\n", d->getScopedName().getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::warning2(WarningCode w, AstDeclaration* d1, AstDeclaration* d2)
+{
+ warningHeader(w);
+ fprintf(stderr, "'%s', '%s'\n", d1->getScopedName().getStr(),
+ d2->getScopedName().getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::syntaxError(ParseState ps, sal_Int32 lineNumber, sal_Char* errmsg)
+{
+ errorHeader(EIDL_SYNTAX_ERROR, lineNumber);
+ fprintf(stderr, "%s%s\n", parseStateToMessage(ps), errmsg + 11);
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::nameCaseError(sal_Char *n, sal_Char *t)
+{
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::coercionError(AstExpression *pExpr, ExprType et)
+{
+ errorHeader(EIDL_COERCION_FAILURE);
+ fprintf(stderr, "'%s' to '%s'\n", pExpr->toString().getStr(),
+ exprTypeToString(et));
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::lookupError(const ::rtl::OString& n)
+{
+ errorHeader(EIDL_LOOKUP_ERROR);
+ fprintf(stderr, "'%s'\n", n.getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::lookupError(ErrorCode e, const ::rtl::OString& n, AstDeclaration* pScope)
+{
+ errorHeader(e);
+ fprintf(stderr, "'%s' in '%s'\n", n.getStr(), pScope->getFullName().getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::flagError(ErrorCode e, sal_uInt32 flag)
+{
+ errorHeader(e);
+ fprintf(stderr, "'%s'\n", flagToString(flag).getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::noTypeError(AstDeclaration* pDecl)
+{
+ errorHeader(EIDL_NOT_A_TYPE);
+ fprintf(stderr, "'%s'\n", pDecl->getScopedName().getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::inheritanceError(OString* name, AstDeclaration* pDecl)
+{
+ if ( (pDecl->getNodeType() == NT_interface) &&
+ !((AstInterface*)pDecl)->isDefined() )
+ {
+ errorHeader(EIDL_INHERIT_FWD_ERROR);
+ fprintf(stderr, "interface '%s' cannot inherit from forward declared interface '%s'\n",
+ name->getStr(), pDecl->getScopedName().getStr());
+ } else
+ {
+ errorHeader(EIDL_CANT_INHERIT);
+ fprintf(stderr, "interface '%s' attempts to inherit from '%s'\n",
+ name->getStr(), pDecl->getScopedName().getStr());
+ }
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::forwardLookupError(AstDeclaration* pForward,
+ const ::rtl::OString& name)
+{
+ errorHeader(EIDL_FWD_DECL_LOOKUP);
+ fprintf(stderr, "trying to look up '%s' in undefined forward declared interface '%s'\n",
+ pForward->getScopedName().getStr(), name.getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::constantExpected(AstDeclaration* pDecl,
+ const ::rtl::OString& name)
+{
+ errorHeader(EIDL_CONSTANT_EXPECTED);
+ fprintf(stderr, "'%s' is bound to '%s'\n", name.getStr(), pDecl->getScopedName().getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::evalError(AstExpression* pExpr)
+{
+ errorHeader(EIDL_EVAL_ERROR);
+ fprintf(stderr, "'%s'\n", pExpr->toString().getStr());
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::enumValExpected(AstUnion* pUnion, AstUnionLabel *pLabel)
+{
+ errorHeader(EIDL_ENUM_VAL_EXPECTED);
+ fprintf(stderr, " union %s, ", pUnion->getLocalName().getStr());
+// pLabel->dump();
+ fprintf(stderr, "\n");
+ idlc()->incErrorCount();
+}
+
+void ErrorHandler::enumValLookupFailure(AstUnion* pUnion, AstEnum* pEnum, const ::rtl::OString& name)
+{
+ errorHeader(EIDL_ENUM_VAL_NOT_FOUND);
+ fprintf(stderr, " union %s, enum %s, enumerator %s\n",
+ pUnion->getLocalName().getStr(),
+ pEnum->getLocalName().getStr(), name.getStr());
+ idlc()->incErrorCount();
+}
diff --git a/idlc/source/fehelper.cxx b/idlc/source/fehelper.cxx
new file mode 100644
index 000000000000..66314369016d
--- /dev/null
+++ b/idlc/source/fehelper.cxx
@@ -0,0 +1,192 @@
+/*************************************************************************
+ *
+ * $RCSfile: fehelper.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_FEHELPER_HXX_
+#include <idlc/fehelper.hxx>
+#endif
+#ifndef _IDLC_ERRORHANDLER_HXX_
+#include <idlc/errorhandler.hxx>
+#endif
+#ifndef _IDLC_ASTARRAY_HXX_
+#include <idlc/astarray.hxx>
+#endif
+
+using namespace ::rtl;
+
+FeDeclarator::FeDeclarator(const OString& name, DeclaratorType declType, AstDeclaration* pComplPart)
+ : m_pComplexPart(pComplPart)
+ , m_name(name)
+ , m_declType(declType)
+{
+}
+
+FeDeclarator::~FeDeclarator()
+{
+}
+
+sal_Bool FeDeclarator::checkType(AstDeclaration *type)
+{
+ OString tmp(m_name);
+ sal_uInt32 count = 0;
+ if ( (count = m_name.getTokenCount(':')) > 0 )
+ tmp = m_name.getToken(count-1, ':');
+
+ if (tmp == type->getLocalName())
+ return sal_False;
+ else
+ return sal_True;
+}
+
+AstType* FeDeclarator::compose(AstDeclaration* pDecl)
+{
+ AstArray* pArray;
+ AstType* pType;
+
+ if ( !pDecl->isType() )
+ {
+ idlc()->error()->noTypeError(pDecl);
+ return NULL;
+ }
+ pType = (AstType*)pDecl;
+ if (m_declType == FD_simple || m_pComplexPart == NULL)
+ return pType;
+
+ if (m_pComplexPart->getNodeType() == NT_array)
+ {
+ pArray = (AstArray*)m_pComplexPart;
+ pArray->setType(pType);
+
+ // insert array type in global scope
+ AstScope* pScope = idlc()->scopes()->bottom();
+ AstDeclaration* pDecl = NULL;
+ if ( pScope )
+ {
+ pDecl = pScope->addDeclaration(pArray);
+ if ( (AstDeclaration*)pArray != pDecl )
+ {
+ delete m_pComplexPart;
+ m_pComplexPart = pDecl;
+ }
+ }
+ return pArray;
+ }
+
+ return NULL; // return through this statement should not happen
+}
+
+FeInheritanceHeader::FeInheritanceHeader(NodeType nodeType, ::rtl::OString* pName, StringList* pInherits)
+ : m_nodeType(nodeType)
+ , m_pName(pName)
+ , m_pInherits(NULL)
+{
+ initializeInherits(pInherits);
+}
+
+sal_Bool FeInheritanceHeader::initializeInherits(StringList* pInherits)
+{
+ if ( pInherits && (pInherits->size() > 0) )
+ {
+ StringList::iterator iter = pInherits->begin();
+ StringList::iterator end = pInherits->end();
+ AstScope* pScope = idlc()->scopes()->topNonNull();
+ AstDeclaration* pDecl = NULL;
+
+ m_pInherits = new DeclList();
+ while (pScope && iter != end)
+ {
+ pDecl = pScope->lookupByName(*iter);
+ if ( pDecl )
+ {
+ m_pInherits->push_back(pDecl);
+ } else
+ {
+ idlc()->error()->lookupError(*iter);
+ return sal_False;
+ }
+ iter++;
+ }
+ }
+ return sal_True;
+}
+
+sal_Bool FeInterfaceHeader::initializeInherits(StringList* pInherits)
+{
+ if ( !pInherits )
+ return sal_True;
+
+ if ( !FeInheritanceHeader::initializeInherits(pInherits) )
+ return sal_False;
+
+ DeclList::iterator iter = m_pInherits->begin();
+ DeclList::iterator end = m_pInherits->end();
+
+ while ( iter != end )
+ {
+ AstInterface* pIface = ((AstInterface*)*iter);
+ if ( ((*iter)->getNodeType() != NT_interface) ||
+ !((AstInterface*)*iter)->isDefined() )
+ {
+ idlc()->error()->inheritanceError(getName(), *iter);
+ return sal_False;
+ }
+ iter++;
+ }
+ return sal_True;
+}
diff --git a/idlc/source/idlc.cxx b/idlc/source/idlc.cxx
new file mode 100644
index 000000000000..756ca6ae5f28
--- /dev/null
+++ b/idlc/source/idlc.cxx
@@ -0,0 +1,323 @@
+/*************************************************************************
+ *
+ * $RCSfile: idlc.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_IDLC_HXX_
+#include <idlc/idlc.hxx>
+#endif
+
+#ifndef _IDLC_ERRORHANDLER_HXX_
+#include <idlc/errorhandler.hxx>
+#endif
+#ifndef _IDLC_ASTSCOPE_HXX_
+#include <idlc/astscope.hxx>
+#endif
+#ifndef _IDLC_ASTMODULE_HXX_
+#include <idlc/astmodule.hxx>
+#endif
+#ifndef _IDLC_ASTSERVICE_HXX_
+#include <idlc/astservice.hxx>
+#endif
+#ifndef _IDLC_ASTCONSTANTS_HXX_
+#include <idlc/astconstants.hxx>
+#endif
+#ifndef _IDLC_ASTEXCEPTION_HXX_
+#include <idlc/astexception.hxx>
+#endif
+#ifndef _IDLC_ASTUNION_HXX_
+#include <idlc/astunion.hxx>
+#endif
+#ifndef _IDLC_ASTENUM_HXX_
+#include <idlc/astenum.hxx>
+#endif
+#ifndef _IDLC_ASTINTERFACE_HXX_
+#include <idlc/astinterface.hxx>
+#endif
+#ifndef _IDLC_ASTOPERATION_HXX_
+#include <idlc/astoperation.hxx>
+#endif
+#ifndef _IDLC_ASTBASETYPE_HXX_
+#include <idlc/astbasetype.hxx>
+#endif
+
+using namespace ::rtl;
+
+AstDeclaration* SAL_CALL scopeAsDecl(AstScope* pScope)
+{
+ if (pScope == NULL) return NULL;
+
+ switch( pScope->getScopeNodeType() )
+ {
+ case NT_service:
+ return (AstService*)(pScope);
+ case NT_module:
+ case NT_root:
+ return (AstModule*)(pScope);
+ case NT_constants:
+ return (AstConstants*)(pScope);
+ case NT_interface:
+ return (AstInterface*)(pScope);
+ case NT_operation:
+ return (AstOperation*)(pScope);
+ case NT_exception:
+ return (AstException*)(pScope);
+ case NT_union:
+ return (AstUnion*)(pScope);
+ case NT_struct:
+ return (AstStruct*)(pScope);
+ case NT_enum:
+ return (AstEnum*)(pScope);
+ default:
+ return NULL;
+ }
+}
+
+AstScope* SAL_CALL declAsScope(AstDeclaration* pDecl)
+{
+ if (pDecl == NULL) return NULL;
+
+ switch(pDecl->getNodeType())
+ {
+ case NT_interface:
+ return (AstInterface*)(pDecl);
+ case NT_service:
+ return (AstService*)(pDecl);
+ case NT_module:
+ case NT_root:
+ return (AstModule*)(pDecl);
+ case NT_constants:
+ return (AstConstants*)(pDecl);
+ case NT_exception:
+ return (AstException*)(pDecl);
+ case NT_union:
+ return (AstUnion*)(pDecl);
+ case NT_struct:
+ return (AstStruct*)(pDecl);
+ case NT_enum:
+ return (AstEnum*)(pDecl);
+ case NT_operation:
+ return (AstOperation*)(pDecl);
+ default:
+ return NULL;
+ }
+}
+
+static void SAL_CALL initializePredefinedTypes(AstModule* pRoot)
+{
+ AstBaseType* pPredefined = NULL;
+ if ( pRoot )
+ {
+ pPredefined = new AstBaseType(ET_long, OString("long"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_ulong, OString("unsigned long"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_hyper, OString("hyper"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_uhyper, OString("unsigned hyper"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_short, OString("short"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_ushort, OString("unsigned short"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_float, OString("float"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_double, OString("double"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_char, OString("char"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_byte, OString("byte"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_any, OString("any"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_string, OString("string"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_type, OString("type"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_boolean, OString("boolean"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+
+ pPredefined = new AstBaseType(ET_void, OString("void"), pRoot);
+ pRoot->addDeclaration(pPredefined);
+ }
+}
+
+Idlc::Idlc(Options* pOptions)
+ : m_pOptions(pOptions)
+ , m_bIsInMainfile(sal_True)
+ , m_errorCount(0)
+ , m_lineNumber(0)
+ , m_parseState(PS_NoState)
+ , m_bIsDocValid(sal_False)
+{
+ m_pScopes = new AstStack();
+ // init root object after construction
+ m_pRoot = NULL;
+ m_pErrorHandler = new ErrorHandler();
+ m_bGenerateDoc = m_pOptions->isValid("-C");
+}
+
+Idlc::~Idlc()
+{
+ if (m_pRoot)
+ delete m_pRoot;
+ if (m_pScopes)
+ delete m_pScopes;
+ if (m_pErrorHandler)
+ delete m_pErrorHandler;
+}
+
+void Idlc::init()
+{
+ if ( m_pRoot )
+ delete m_pRoot;
+
+ m_pRoot = new AstModule(NT_root, OString(), NULL);
+
+ // push the root node on the stack
+ m_pScopes->push(m_pRoot);
+ initializePredefinedTypes(m_pRoot);
+}
+
+void Idlc::reset()
+{
+ m_errorCount = 0;
+ m_lineNumber = 0;
+ m_parseState = PS_NoState;
+
+ m_fileName = OString();
+ m_mainFileName = OString();
+ m_realFileName = OString();
+ m_documentation = OString();
+
+ m_pScopes->clear();
+ if ( m_pRoot)
+ delete m_pRoot;
+
+ m_pRoot = new AstModule(NT_root, OString(), NULL);
+
+ // push the root node on the stack
+ m_pScopes->push(m_pRoot);
+ initializePredefinedTypes(m_pRoot);
+}
+
+sal_Bool Idlc::isDocValid()
+{
+ if ( m_bGenerateDoc )
+ return m_bIsDocValid;
+ return sal_False;;
+}
+
+static Idlc* pStaticIdlc = NULL;
+
+Idlc* SAL_CALL idlc()
+{
+ return pStaticIdlc;
+}
+
+Idlc* SAL_CALL setIdlc(Options* pOptions)
+{
+ if ( pStaticIdlc )
+ {
+ delete pStaticIdlc;
+ }
+ pStaticIdlc = new Idlc(pOptions);
+ pStaticIdlc->init();
+ return pStaticIdlc;
+}
+
+sal_Bool SAL_CALL canBeRedefined(AstDeclaration *pDecl)
+{
+ switch (pDecl->getNodeType())
+ {
+ case NT_module:
+ case NT_constants:
+ case NT_interface:
+ case NT_const:
+ case NT_exception:
+ case NT_parameter:
+ case NT_enum_val:
+ case NT_array:
+ case NT_sequence:
+ case NT_union:
+ case NT_struct:
+ case NT_enum:
+ case NT_typedef:
+// return sal_True;
+ case NT_union_branch:
+ case NT_member:
+ case NT_attribute:
+ case NT_operation:
+ case NT_predefined:
+ default:
+ return sal_False;
+ }
+}
diff --git a/idlc/source/idlccompile.cxx b/idlc/source/idlccompile.cxx
new file mode 100644
index 000000000000..fe446ab4a6d7
--- /dev/null
+++ b/idlc/source/idlccompile.cxx
@@ -0,0 +1,332 @@
+/*************************************************************************
+ *
+ * $RCSfile: idlccompile.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_IDLC_HXX_
+#include <idlc/idlc.hxx>
+#endif
+#ifndef _RTL_USTRING_HXX_
+#include <rtl/ustring.hxx>
+#endif
+#ifndef _RTL_STRBUF_HXX_
+#include <rtl/strbuf.hxx>
+#endif
+
+#ifndef _OSL_PROCESS_H_
+#include <osl/process.h>
+#endif
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
+#if defined(SAL_W32) || defined(SAL_OS2)
+#include <io.h>
+#endif
+
+#ifdef SAL_UNX
+#include <unistd.h>
+#ifdef MACOSX
+#include <sys/wait.h>
+#else
+#include <wait.h>
+#endif
+#endif
+
+using namespace ::rtl;
+
+extern int yyparse();
+extern FILE* yyin;
+extern int yydebug;
+
+sal_Int32 lineNumber = 1;
+
+
+static OUString TMP(RTL_CONSTASCII_USTRINGPARAM("TMP"));
+static OUString TEMP(RTL_CONSTASCII_USTRINGPARAM("TEMP"));
+static sal_Char tmpFilePattern[512];
+
+// prefix must be specified, postfix could be empty string
+OString makeTempName(const OString& prefix, const OString& postfix)
+{
+ OUString uTmpPath;
+ OString tmpPath;
+
+ if ( osl_getEnvironment(TMP.pData, &uTmpPath.pData) != osl_Process_E_None )
+ {
+ if ( osl_getEnvironment(TEMP.pData, &uTmpPath.pData) != osl_Process_E_None )
+ {
+#if defined(SAL_W32) || defined(SAL_OS2)
+ tmpPath = OString("c:\\temp");
+#else
+ tmpPath = OString("/tmp");
+#endif
+ }
+ }
+
+ if ( uTmpPath.getLength() )
+ tmpPath = OUStringToOString(uTmpPath, RTL_TEXTENCODING_UTF8);
+
+#if defined(SAL_W32) || defined(SAL_UNX)
+ strcpy(tmpFilePattern, tmpPath);
+#ifdef SAL_UNX
+ strcat(tmpFilePattern, "/");
+#else
+ strcat(tmpFilePattern, "\\");
+#endif
+ strcat(tmpFilePattern, prefix.getStr());
+ strcat(tmpFilePattern, "XXXXXX");
+
+ (void) mktemp(tmpFilePattern);
+ if ( postfix.getLength() )
+ strcat(tmpFilePattern, postfix.getStr());
+#endif
+
+#ifdef __OS2__
+ strcpy(tmpFilePattern, tempnam(NULL, prefix.getStr());
+#endif
+
+ return OString(tmpFilePattern);
+}
+
+void copyFile(const OString& sourceFile, const OString& targetFile)
+{
+ FILE* pSource = fopen(sourceFile.getStr(), "r");
+
+ if ( !pSource )
+ {
+ fprintf(stderr, "%s: couldn't open file: %s\n",
+ idlc()->getOptions()->getProgramName().getStr(), sourceFile.getStr());
+ exit(99);
+ }
+
+ FILE* pTarget = fopen(targetFile.getStr(), "w");
+
+ if ( !pTarget )
+ {
+ fprintf(stderr, "%s: couldn't create file: %s\n",
+ idlc()->getOptions()->getProgramName().getStr(), targetFile.getStr());
+ exit(99);
+ }
+
+ sal_Char pBuffer[513];
+
+ fgets(pBuffer, 512, pSource);
+ while ( !feof(pSource) )
+ {
+ fprintf(pTarget, "%s", pBuffer);
+ fgets(pBuffer, 512, pSource);
+ }
+
+ fclose(pSource);
+ fclose(pTarget);
+}
+
+sal_Int32 compileFile(const OString& fileName)
+{
+ // preporcess input file
+ OString tmpFile = makeTempName(OString("idli_"), OString(".idl"));
+ OString preprocFile = makeTempName(OString("idlf_"), OString(".idl"));
+
+ copyFile(fileName, tmpFile);
+
+ idlc()->setFileName(fileName);
+ idlc()->setMainFileName(fileName);
+ idlc()->setRealFileName(tmpFile);
+
+ OStringBuffer cppArgs(512);
+ cppArgs.append("-DIDL -Xi -Xc -+ -I.");
+ Options* pOptions = idlc()->getOptions();
+
+ OString filePath;
+#if defined(SAL_W32) || defined(SAL_OS2)
+ sal_uInt32 index = fileName.lastIndexOf('\\');
+#else
+ sal_uInt32 index = fileName.lastIndexOf('/');
+#endif
+ if ( index > 0)
+ {
+ filePath = fileName.copy(0, index);
+
+ if ( filePath.getLength() )
+ {
+ cppArgs.append(" -I");
+ cppArgs.append(filePath);
+ }
+ }
+
+ if ( pOptions->isValid("-D") )
+ {
+ cppArgs.append(" ");
+ cppArgs.append(pOptions->getOption("-D"));
+ }
+ if ( pOptions->isValid("-I") )
+ {
+ cppArgs.append(" ");
+ cppArgs.append(pOptions->getOption("-I"));
+ }
+
+ cppArgs.append(" ");
+ cppArgs.append(tmpFile);
+ cppArgs.append(" ");
+ cppArgs.append(preprocFile);
+
+ OString cmdFileName = makeTempName(OString("idlc_"), OString());
+ FILE* pCmdFile = fopen(cmdFileName, "w");
+
+ if ( !pCmdFile )
+ {
+ fprintf(stderr, "%s: couldn't open temporary file for preprocessor commands: %s\n",
+ idlc()->getOptions()->getProgramName().getStr(), cmdFileName.getStr());
+ exit(99);
+ }
+ fprintf(pCmdFile, "%s", cppArgs.getStr());
+ fclose(pCmdFile);
+
+ OUString cmdArg(RTL_CONSTASCII_USTRINGPARAM("@"));
+ cmdArg += OStringToOUString(cmdFileName, RTL_TEXTENCODING_UTF8);
+
+ OUString cpp;
+ OUString startDir;
+ OSL_VERIFY(osl_getExecutableFile(&cpp.pData) == osl_Process_E_None);
+
+#if defined(SAL_W32) || defined(SAL_OS2)
+ cpp = cpp.copy(0, cpp.getLength() - 8);
+ cpp += OUString( RTL_CONSTASCII_USTRINGPARAM("idlcpp.exe"));
+#else
+ cpp = cpp.copy(0, cpp.getLength() - 4);
+ cpp += OUString( RTL_CONSTASCII_USTRINGPARAM("idlcpp"));
+#endif
+
+ oslProcess hProcess = NULL;
+ oslProcessError procError = osl_Process_E_None;
+
+ procError = osl_executeProcess(cpp.pData, &cmdArg.pData, 1, osl_Process_WAIT,
+ 0, startDir.pData, 0, 0, 0, &hProcess);
+
+ oslProcessInfo hInfo;
+ hInfo.Size = sizeof(oslProcessInfo);
+ OSL_VERIFY( osl_getProcessInfo(hProcess, osl_Process_EXITCODE, &hInfo) == osl_Process_E_None );
+
+ if ( procError || (hInfo.Code != 0) )
+ {
+ if ( procError != osl_Process_E_None )
+ fprintf(stderr, "%s: starting preprocessor failed\n", pOptions->getProgramName().getStr());
+ else
+ fprintf(stderr, "%s: preprocessing \"%s\" failed\n", pOptions->getProgramName().getStr(), fileName.getStr());
+
+ unlink(tmpFile.getStr());
+ unlink(preprocFile.getStr());
+ unlink(cmdFileName.getStr());
+ osl_freeProcessHandle(hProcess);
+ exit(hInfo.Code ? hInfo.Code : 99);
+ }
+ osl_freeProcessHandle(hProcess);
+
+ if (unlink(tmpFile.getStr()) != 0)
+ {
+ fprintf(stderr, "%s: Could not remove cpp input file %s\n",
+ pOptions->getProgramName(), tmpFile.getStr());
+ exit(99);
+ }
+
+ if (unlink(cmdFileName.getStr()) != 0)
+ {
+ fprintf(stderr, "%s: Could not remove unocpp command file %s\n",
+ pOptions->getProgramName(), cmdFileName.getStr());
+
+ exit(99);
+ }
+
+ if ( pOptions->isValid("-E") )
+ {
+ if (unlink(preprocFile) != 0)
+ {
+ fprintf(stderr, "%s: Could not remove parser input file %s\n",
+ pOptions->getProgramName(), preprocFile.getStr());
+ exit(99);
+ }
+ exit(0);
+ }
+
+ // parse file
+ yyin = fopen(preprocFile.getStr(), "r");
+ if (yyin == NULL)
+ {
+ fprintf(stderr, "%s: Could not open cpp output file %s\n",
+ pOptions->getProgramName(), preprocFile.getStr());
+ exit(99);
+ }
+
+ //yydebug = 0 no trace information
+ //yydebug = 1 parser produce trace information
+ yydebug = 0;
+
+ sal_Int32 nErrors = yyparse();
+ nErrors = idlc()->getErrorCount();
+
+ fclose(yyin);
+ if (unlink(preprocFile.getStr()) != 0)
+ {
+ fprintf(stderr, "%s: Could not remove parser input file %s\n",
+ pOptions->getProgramName(), preprocFile.getStr());
+ exit(99);
+ }
+
+ return nErrors;
+}
diff --git a/idlc/source/idlcmain.cxx b/idlc/source/idlcmain.cxx
new file mode 100644
index 000000000000..e54b673091e1
--- /dev/null
+++ b/idlc/source/idlcmain.cxx
@@ -0,0 +1,135 @@
+/*************************************************************************
+ *
+ * $RCSfile: idlcmain.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_IDLC_HXX_
+#include <idlc/idlc.hxx>
+#endif
+
+#ifdef SAL_UNX
+sal_Char SEPERATOR = '/';
+#else
+sal_Char SEPERATOR = '\\';
+#endif
+
+using namespace ::rtl;
+
+void SAL_CALL main( int argc, char** argv )
+{
+ Options options;
+
+ try
+ {
+ if (!options.initOptions(argc, argv))
+ exit(1);
+ }
+ catch( IllegalArgument& e)
+ {
+ fprintf(stderr, "Illegal argument: %s\n%s",
+ e.m_message.getStr(),
+ options.prepareVersion().getStr());
+ exit(99);
+ }
+
+ setIdlc(&options);
+
+ const StringVector& files = options.getInputFiles();
+ sal_Int32 nFiles = files.size();
+ sal_Int32 nErrors = 0;
+ for ( sal_Int32 i=0; i < nFiles; i++ )
+ {
+ fprintf(stdout, "%s: compile '%s' ... \n",
+ options.getProgramName().getStr(), files[i].getStr());
+ nErrors = compileFile(files[i]);
+ if ( nErrors )
+ {
+ OString outputName;
+ if ( options.isValid("-O") )
+ {
+ outputName = options.getOption("-O");
+ sal_Char c = outputName.getStr()[outputName.getLength()-1];
+
+ if ( c != SEPERATOR )
+ outputName += OString::valueOf(SEPERATOR);
+ }
+
+ OString strippedFileName(files[i].copy(files[i].lastIndexOf(SEPERATOR) + 1));
+ outputName += strippedFileName.replaceAt(strippedFileName.getLength() -3 , 3, "urd");
+ removeIfExists(outputName);
+ } else
+ nErrors = produceFile(files[i]);
+
+ idlc()->reset();
+ if ( nErrors > 0 )
+ break;
+ }
+
+ if ( nErrors > 0 )
+ {
+ fprintf(stdout, "%s: detected %d errors in file '%s'%s",
+ options.getProgramName().getStr(), nErrors,
+ files[i].getStr(), options.prepareVersion().getStr());
+ } else
+ {
+ fprintf(stdout, "%s: returned with %d errors%s",
+ options.getProgramName().getStr(), nErrors,
+ options.prepareVersion().getStr());
+ }
+ exit(nErrors);
+}
diff --git a/idlc/source/idlcproduce.cxx b/idlc/source/idlcproduce.cxx
new file mode 100644
index 000000000000..01fa11e9ba6c
--- /dev/null
+++ b/idlc/source/idlcproduce.cxx
@@ -0,0 +1,284 @@
+/*************************************************************************
+ *
+ * $RCSfile: idlcproduce.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _IDLC_IDLC_HXX_
+#include <idlc/idlc.hxx>
+#endif
+#ifndef _IDLC_ASTMODULE_HXX_
+#include <idlc/astmodule.hxx>
+#endif
+#ifndef _RTL_STRBUF_HXX_
+#include <rtl/strbuf.hxx>
+#endif
+
+#if defined(SAL_W32) || defined(SAL_OS2)
+#include <io.h>
+#include <direct.h>
+#include <errno.h>
+#endif
+
+#ifdef SAL_UNX
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#endif
+
+#ifdef SAL_UNX
+extern sal_Char SEPERATOR;
+#else
+extern sal_Char SEPERATOR;
+#endif
+
+using namespace ::rtl;
+
+StringList* pCreatedDirectories = NULL;
+
+static sal_Bool checkOutputPath(const OString& completeName)
+{
+ OStringBuffer buffer(completeName.getLength());
+ sal_Int32 count = completeName.getTokenCount(SEPERATOR) - 1;
+ sal_Int32 offset=0;
+
+ if ( !count )
+ return sal_True;
+
+ OString token(completeName.getToken(0, SEPERATOR));
+ const sal_Char* p = token.getStr();
+ if (strcmp(p, "..") == 0
+ || *(p+1) == ':'
+ || strcmp(p, ".") == 0)
+ {
+ offset++;
+ buffer.append(token);
+ buffer.append(SEPERATOR);
+ }
+
+ for (sal_Int32 i=offset; i < count; i++)
+ {
+ buffer.append(completeName.getToken(i, SEPERATOR));
+
+ if ( buffer.getLength() > 0 )
+ {
+#ifdef SAL_UNX
+ if (mkdir((char*)buffer.getStr(), 0777) == -1)
+#else
+ if (mkdir((char*)buffer.getStr()) == -1)
+#endif
+ {
+ if (errno == ENOENT)
+ {
+ fprintf(stderr, "%s: cannot create directory '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(), buffer.getStr());
+ return sal_False;
+ }
+ } else
+ {
+ if ( !pCreatedDirectories )
+ pCreatedDirectories = new StringList();
+ pCreatedDirectories->push_front(buffer.getStr());
+ }
+ }
+ if ( i+1 < count )
+ buffer.append(SEPERATOR);
+ }
+ return sal_True;
+}
+
+static sal_Bool cleanPath()
+{
+ if ( pCreatedDirectories )
+ {
+ StringList::iterator iter = pCreatedDirectories->begin();
+ StringList::iterator end = pCreatedDirectories->end();
+ while ( iter != end )
+ {
+//#ifdef SAL_UNX
+// if (rmdir((char*)(*iter).getStr(), 0777) == -1)
+//#else
+ if (rmdir((char*)(*iter).getStr()) == -1)
+//#endif
+ {
+ fprintf(stderr, "%s: cannot remove directory '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(), (*iter).getStr());
+ return sal_False;
+ }
+ iter++;
+ }
+ delete pCreatedDirectories;
+ }
+ return sal_True;
+}
+
+void SAL_CALL removeIfExists(const OString& fileName)
+{
+ FILE* pDest = fopen(fileName.getStr(), "r");
+ if ( pDest )
+ {
+ fclose(pDest);
+ unlink(fileName.getStr());
+ }
+}
+
+sal_Int32 SAL_CALL produceFile(const OString& fileName)
+{
+ Options* pOptions = idlc()->getOptions();
+
+ OString regFileName;
+ if ( pOptions->isValid("-O") )
+ {
+ regFileName = pOptions->getOption("-O");
+ sal_Char c = regFileName.getStr()[regFileName.getLength()-1];
+
+ if ( c != SEPERATOR )
+ regFileName += OString::valueOf(SEPERATOR);
+ }
+
+ OString regTmpName(regFileName);
+ OString strippedFileName(fileName.copy(fileName.lastIndexOf(SEPERATOR) + 1));
+ regFileName += strippedFileName.replaceAt(strippedFileName.getLength() -3 , 3, "urd");
+ regTmpName += strippedFileName.replaceAt(strippedFileName.getLength() -3 , 3, "_idlc_");
+
+ if ( !checkOutputPath(regTmpName) )
+ {
+ fprintf(stderr, "%s: could not create path of registry file '%s'.\n",
+ pOptions->getProgramName().getStr(), regFileName.getStr());
+ removeIfExists(regFileName);
+ return 1;
+ }
+
+ RegistryLoader regLoader;
+ RegistryTypeWriterLoader writerLoader;
+
+ if ( !regLoader.isLoaded() || !writerLoader.isLoaded() )
+ {
+ fprintf(stderr, "%s: could not load registry dll.\n",
+ pOptions->getProgramName().getStr());
+ removeIfExists(regFileName);
+ cleanPath();
+ return 1;
+ }
+
+ Registry regFile(regLoader);
+
+ removeIfExists(regTmpName);
+ if ( regFile.create(OStringToOUString(regTmpName, RTL_TEXTENCODING_UTF8)) )
+ {
+ fprintf(stderr, "%s: could not create registry file '%s'\n",
+ pOptions->getProgramName().getStr(), regTmpName.getStr());
+ removeIfExists(regTmpName);
+ removeIfExists(regFileName);
+ cleanPath();
+ return 1;
+ }
+
+ RegistryKey rootKey;
+ if ( regFile.openRootKey(rootKey) )
+ {
+ fprintf(stderr, "%s: could not open root of registry file '%s'\n",
+ pOptions->getProgramName().getStr(), regFileName.getStr());
+ removeIfExists(regTmpName);
+ removeIfExists(regFileName);
+ cleanPath();
+ return 1;
+ }
+
+ // produce registry file
+ if ( !idlc()->getRoot()->dump(rootKey, &writerLoader) )
+ {
+ rootKey.closeKey();
+ regFile.close();
+ regFile.destroy(OStringToOUString(regFileName, RTL_TEXTENCODING_UTF8));
+ removeIfExists(regFileName);
+ cleanPath();
+ return 1;
+ }
+
+ if ( rootKey.closeKey() )
+ {
+ fprintf(stderr, "%s: could not close root of registry file '%s'\n",
+ pOptions->getProgramName().getStr(), regFileName.getStr());
+ removeIfExists(regTmpName);
+ removeIfExists(regFileName);
+ cleanPath();
+ return 1;
+ }
+ if ( regFile.close() )
+ {
+ fprintf(stderr, "%s: could not close registry file '%s'\n",
+ pOptions->getProgramName().getStr(), regFileName.getStr());
+ removeIfExists(regTmpName);
+ removeIfExists(regFileName);
+ cleanPath();
+ return 1;
+ }
+
+ removeIfExists(regFileName);
+ if ( rename(regTmpName.getStr(), regFileName.getStr()) != 0 )
+ {
+ fprintf(stderr, "%s: cannot rename temporary registry '%s' to '%s'\n",
+ idlc()->getOptions()->getProgramName().getStr(),
+ regTmpName.getStr(), regFileName.getStr());
+ removeIfExists(regTmpName);
+ cleanPath();
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/idlc/source/makefile.mk b/idlc/source/makefile.mk
new file mode 100644
index 000000000000..7d0ce6f8054d
--- /dev/null
+++ b/idlc/source/makefile.mk
@@ -0,0 +1,147 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1 $
+#
+# last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#
+#
+#*************************************************************************
+
+PRJ=..
+
+PRJNAME=idlc
+TARGET=idlc
+TARGETTYPE=CUI
+LIBTARGET=NO
+
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+
+.INCLUDE : svpre.mk
+.INCLUDE : settings.mk
+.INCLUDE : sv.mk
+
+
+# --- Files --------------------------------------------------------
+
+CXXFILES= \
+ $(MISC)$/scanner.cxx \
+ $(MISC)$/parser.cxx \
+ idlcmain.cxx \
+ idlc.cxx \
+ idlccompile.cxx \
+ idlcproduce.cxx \
+ errorhandler.cxx \
+ options.cxx \
+ fehelper.cxx \
+ astdeclaration.cxx \
+ astscope.cxx \
+ aststack.cxx \
+ astdump.cxx \
+ astinterface.cxx \
+ aststruct.cxx \
+ astoperation.cxx \
+ astconstant.cxx \
+ astenum.cxx \
+ astarray.cxx \
+ astunion.cxx \
+ astexpression.cxx
+
+OBJFILES= \
+ $(OBJ)$/scanner.obj \
+ $(OBJ)$/parser.obj \
+ $(OBJ)$/idlcmain.obj \
+ $(OBJ)$/idlc.obj \
+ $(OBJ)$/idlccompile.obj \
+ $(OBJ)$/idlcproduce.obj \
+ $(OBJ)$/errorhandler.obj \
+ $(OBJ)$/options.obj \
+ $(OBJ)$/fehelper.obj \
+ $(OBJ)$/astdeclaration.obj \
+ $(OBJ)$/astscope.obj \
+ $(OBJ)$/aststack.obj \
+ $(OBJ)$/astdump.obj \
+ $(OBJ)$/astinterface.obj \
+ $(OBJ)$/aststruct.obj \
+ $(OBJ)$/astoperation.obj \
+ $(OBJ)$/astconstant.obj \
+ $(OBJ)$/astenum.obj \
+ $(OBJ)$/astarray.obj \
+ $(OBJ)$/astunion.obj \
+ $(OBJ)$/astexpression.obj
+
+APP1TARGET= $(TARGET)
+APP1OBJS= $(OBJFILES)
+
+APP1STDLIBS=\
+ $(SALLIB) \
+ $(SALHELPERLIB)
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+
+
+$(MISC)$/scanner.cxx: scanner.ll
+ +flex -o$(MISC)$/scanner.cxx scanner.ll
+
+$(MISC)$/parser.cxx: parser.yy
+ +bison -v -d -o$(MISC)$/parser.cxx parser.yy
+ +$(COPY) $(MISC)$/parser.cxx.h $(OUT)$/inc$/parser.h
+# with line statements (for debugging)
+# +bison -v -d -o$(MISC)$/parser.cxx parser.yy
diff --git a/idlc/source/options.cxx b/idlc/source/options.cxx
new file mode 100644
index 000000000000..062f43d73c1c
--- /dev/null
+++ b/idlc/source/options.cxx
@@ -0,0 +1,372 @@
+/*************************************************************************
+ *
+ * $RCSfile: options.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#include <stdio.h>
+
+#ifndef _IDLC_OPTIONS_HXX_
+#include <idlc/options.hxx>
+#endif
+
+using namespace rtl;
+
+Options::Options()
+{
+}
+
+Options::~Options()
+{
+
+}
+
+sal_Bool Options::initOptions(int ac, char* av[], sal_Bool bCmdFile)
+ throw( IllegalArgument )
+{
+ sal_Bool ret = sal_True;
+ sal_uInt16 i=0;
+
+ if (!bCmdFile)
+ {
+ bCmdFile = sal_True;
+
+ m_program = av[0];
+
+ if (ac < 2)
+ {
+ fprintf(stderr, "%s", prepareHelp().getStr());
+ ret = sal_False;
+ }
+
+ i = 1;
+ } else
+ {
+ i = 0;
+ }
+
+ char *s=NULL;
+ for (i; i < ac; i++)
+ {
+ if (av[i][0] == '-')
+ {
+ switch (av[i][1])
+ {
+ case 'O':
+ if (av[i][2] == '\0')
+ {
+ if (i < ac - 1 && av[i+1][0] != '-')
+ {
+ i++;
+ s = av[i];
+ } else
+ {
+ OString tmp("'-O', please check");
+ if (i <= ac - 1)
+ {
+ tmp += " your input '" + OString(av[i+1]) + "'";
+ }
+
+ throw IllegalArgument(tmp);
+ }
+ } else
+ {
+ s = av[i] + 2;
+ }
+
+ m_options["-O"] = OString(s);
+ break;
+ case 'I':
+ {
+ if (av[i][2] == '\0')
+ {
+ if (i < ac - 1 && av[i+1][0] != '-')
+ {
+ i++;
+ s = av[i];
+ } else
+ {
+ OString tmp("'-I', please check");
+ if (i <= ac - 1)
+ {
+ tmp += " your input '" + OString(av[i+1]) + "'";
+ }
+
+ throw IllegalArgument(tmp);
+ }
+ } else
+ {
+ s = av[i] + 2;
+ }
+
+ OString inc(s);
+ if ( inc.indexOf(';') > 0 )
+ {
+ OString tmp(s);
+ sal_Int32 count = tmp.getTokenCount(';');
+ inc = OString();
+ for (sal_Int32 i=0; i < count; i++)
+ inc = inc + " -I" + tmp.getToken(i, ';');
+ } else
+ inc = OString("-I") + s;
+
+ if (m_options.count("-I") > 0)
+ {
+ OString tmp(m_options["-I"]);
+ tmp = tmp + " " + inc;
+ m_options["-I"] = tmp;
+ } else
+ {
+ m_options["-I"] = inc;
+ }
+ }
+ break;
+ case 'D':
+ if (av[i][2] == '\0')
+ {
+ if (i < ac - 1 && av[i+1][0] != '-')
+ {
+ i++;
+ s = av[i];
+ } else
+ {
+ OString tmp("'-D', please check");
+ if (i <= ac - 1)
+ {
+ tmp += " your input '" + OString(av[i+1]) + "'";
+ }
+
+ throw IllegalArgument(tmp);
+ }
+ } else
+ {
+ s = av[i];
+ }
+
+ if (m_options.count("-D") > 0)
+ {
+ OString tmp(m_options["-D"]);
+ tmp = tmp + " " + s;
+ m_options["-D"] = tmp;
+ } else
+ {
+ m_options["-D"] = OString(s);
+ }
+ break;
+ case 'C':
+ if (av[i][2] != '\0')
+ {
+ throw IllegalArgument(OString(av[i]) + ", please check your input");
+ }
+ if (m_options.count("-C") == 0)
+ {
+ m_options["-C"] = OString(s);
+ }
+ break;
+ case 'h':
+ case '?':
+ if (av[i][2] != '\0')
+ {
+ throw IllegalArgument(OString(av[i]) + ", please check your input");
+ } else
+ {
+ fprintf(stdout, "%s", prepareHelp().getStr());
+ exit(0);
+ }
+ break;
+ default:
+ throw IllegalArgument("the option is unknown" + OString(av[i]));
+ break;
+ }
+ } else
+ {
+ if (av[i][0] == '@')
+ {
+ FILE* cmdFile = fopen(av[i]+1, "r");
+ if( cmdFile == NULL )
+ {
+ fprintf(stderr, "%s", prepareHelp().getStr());
+ ret = sal_False;
+ } else
+ {
+ int rargc=0;
+ char* rargv[512];
+ char buffer[512];
+
+ while ( fscanf(cmdFile, "%s", buffer) != EOF )
+ {
+ rargv[rargc]= strdup(buffer);
+ rargc++;
+ }
+ fclose(cmdFile);
+
+ ret = initOptions(rargc, rargv, bCmdFile);
+
+ for (long i=0; i < rargc; i++)
+ {
+ free(rargv[i]);
+ }
+ }
+ } else
+ {
+ OString name(av[i]);
+ name = name.toLowerCase();
+ if ( name.lastIndexOf(".idl") != (name.getLength() - 4) )
+ {
+ throw IllegalArgument("'" + OString(av[i]) +
+ "' is not a valid input file, only '*.idl' files will be accepted");
+ }
+ m_inputFiles.push_back(av[i]);
+ }
+ }
+ }
+
+ return ret;
+}
+
+OString Options::prepareHelp()
+{
+ OString help("\nusing: ");
+ help += m_program + " [-options] file_1 ... file_n | @<filename>\n";
+ help += " file_n = file_n specifies one or more idl files.\n";
+ help += " Only files with the extension '.idl' are valid.\n";
+ help += " @<filename> = filename specifies the name of a command file.\n";
+ help += " Options:\n";
+ help += " -O<path> = path describes the output directory.\n";
+ help += " The generated output is a registry file with\n";
+ help += " the same name as the idl input file.\n";
+ help += " -I<path> = path specifies a directory where are include\n";
+ help += " files will be searched by the preprcessor.\n";
+ help += " Multible directories could be combined with ';'.\n";
+ help += " -D<name> = name defines a macro for the preprocessor.\n";
+ help += " -C = generate complete type information, including\n";
+ help += " additional service information and documentation.\n";
+ help += " -h|-? = print this help message and exit.\n";
+ help += prepareVersion();
+
+ return help;
+}
+
+OString Options::prepareVersion()
+{
+ OString version("\nSun Microsystems (R) ");
+ version += m_program + " Version 1.0\n\n";
+ return version;
+}
+
+const OString& Options::getProgramName() const
+{
+ return m_program;
+}
+
+sal_uInt16 Options::getNumberOfOptions() const
+{
+ return m_options.size();
+}
+
+sal_Bool Options::isValid(const OString& option)
+{
+ return (m_options.count(option) > 0);
+}
+
+const OString Options::getOption(const OString& option)
+ throw( IllegalArgument )
+{
+ const OString ret;
+
+ if (m_options.count(option) > 0)
+ {
+ return m_options[option];
+ } else
+ {
+ throw IllegalArgument("Option is not valid or currently not set.");
+ }
+
+ return ret;
+}
+
+const OptionMap& Options::getOptions()
+{
+ return m_options;
+}
+
+sal_uInt16 Options::getNumberOfInputFiles() const
+{
+ return m_inputFiles.size();
+}
+
+const OString Options::getInputFile(sal_uInt16 index)
+ throw( IllegalArgument )
+{
+ const OString ret;
+
+ if (index < m_inputFiles.size())
+ {
+ return m_inputFiles[index];
+ } else
+ {
+ throw IllegalArgument("index is out of bound.");
+ }
+
+ return ret;
+}
+
+const StringVector& Options::getInputFiles()
+{
+ return m_inputFiles;
+}
+
diff --git a/idlc/source/scanner.ll b/idlc/source/scanner.ll
new file mode 100644
index 000000000000..c6c0478a7eb9
--- /dev/null
+++ b/idlc/source/scanner.ll
@@ -0,0 +1,466 @@
+/*************************************************************************
+ *
+ * $RCSfile: scanner.ll,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: jsc $ $Date: 2001-03-15 12:30:43 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+%{
+/*
+ * scanner.ll - Lexical scanner for IDLC 1.0
+ */
+#include <ctype.h>
+
+#ifndef _IDLC_IDLC_HXX_
+#include <idlc/idlc.hxx>
+#endif
+#ifndef _IDLC_FEHELPER_HXX_
+#include <idlc/fehelper.hxx>
+#endif
+
+class AstExpression;
+class AstArray;
+class AstMember;
+
+#include <parser.h>
+
+sal_Int32 beginLine = 0;
+::rtl::OString docu;
+
+static sal_Int64 asciiToInteger( sal_Int8 base, const sal_Char *s )
+{
+ sal_Int64 r = 0;
+ sal_Int64 negative = 0;
+
+ if (*s == '-')
+ {
+ negative = 1;
+ s++;
+ }
+ if (base == 8 && *s == '0')
+ s++;
+ else if (base == 16 && *s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))
+ s += 2;
+
+ for (; *s; s++)
+ {
+ if (*s <= '9' && *s >= '0')
+ r = (r * base) + (*s - '0');
+ else if (base > 10 && *s <= 'f' && *s >= 'a')
+ r = (r * base) + (*s - 'a' + 10);
+ else if (base > 10 && *s <= 'F' && *s >= 'A')
+ r = (r * base) + (*s - 'A' + 10);
+ else
+ break;
+ }
+ if (negative) r *= -1;
+ return r;
+}
+
+static double asciiToFloat(const sal_Char *s)
+{
+ sal_Char *h = (sal_Char*)s;
+ double d = 0.0;
+ double f = 0.0;
+ double e, k;
+ sal_Int32 neg = 0, negexp = 0;
+
+ if (*s == '-')
+ {
+ neg = 1;
+ s++;
+ }
+ while (*s >= '0' && *s <= '9')
+ {
+ d = (d * 10) + *s - '0';
+ s++;
+ }
+ if (*s == '.')
+ {
+ s++;
+ e = 10;
+ while (*s >= '0' && *s <= '9')
+ {
+ d += (*s - '0') / (e * 1.0);
+ e *= 10;
+ s++;
+ }
+ }
+ if (*s == 'e' || *s == 'E')
+ {
+ s++;
+ if (*s == '-')
+ {
+ negexp = 1;
+ s++;
+ } else
+ {
+ if (*s == '+')
+ s++;
+ e = 0;
+ while (*s >= '0' && *s <= '9')
+ {
+ e = (e * 10) + *s - '0';
+ s++;
+ }
+ if (e > 0)
+ {
+ for (k = 1; e > 0; k *= 10, e--);
+ if (negexp)
+ d /= k;
+ else
+ d *= k;
+ }
+ }
+ }
+ if (neg) d *= -1.0;
+ return d;
+}
+
+static void idlParsePragma(sal_Char* pPragma)
+{
+ ::rtl::OString pragma(pPragma);
+ sal_Int32 index = pragma.indexOf("include");
+ sal_Char* begin = pPragma + index + 8;
+ sal_Char* offset = begin;
+ while (*offset != ',') offset++;
+ //::rtl::OString include = pragma.copy(index + 8, offset - begin);
+ idlc()->insertInclude(pragma.copy(index + 8, offset - begin));
+}
+
+static void parseLineAndFile(sal_Char* pBuf)
+{
+ sal_Char *r = pBuf;
+ sal_Char *h;
+ sal_Bool bIsInMain = sal_False;
+
+ /* Skip initial '#' */
+ if (*r != '#')
+ return;
+
+ /* Find line number */
+ for (r++; *r == ' ' || *r == '\t' || isalpha(*r); r++);
+ h = r;
+ for (; *r != '\0' && *r != ' ' && *r != '\t'; r++);
+ *r++ = 0;
+ idlc()->setLineNumber((sal_uInt32)asciiToInteger(10, h));
+
+ /* Find file name, if present */
+ for (; *r != '"'; r++)
+ {
+ if (*r == '\n' || *r == '\0')
+ return;
+ }
+ h = ++r;
+ for (; *r != '"'; r++);
+ *r = 0;
+ if (*h == '\0')
+ idlc()->setFileName(::rtl::OString("standard input"));
+ else
+ idlc()->setFileName(::rtl::OString(h));
+
+ bIsInMain = (idlc()->getFileName() == idlc()->getRealFileName()) ? sal_True : sal_False;
+ idlc()->setInMainfile(bIsInMain);
+}
+
+%}
+
+%option noyywrap
+%option never-interactive
+
+%x DOCU
+%x COMMENT
+
+DIGIT [0-9]
+OCT_DIGIT [0-7]
+HEX_DIGIT [a-fA-F0-9]
+ALPHA [a-zA-Z]
+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}|"'")*\"
+
+IDENTIFIER ({ALPHA}|_{ALPHA})({ALPHA}|{DIGIT}|_)*
+
+%%
+
+[ \t\r]+ ; /* eat up whitespace */
+[\n] {
+ idlc()->incLineNumber();
+}
+
+attribute return IDL_ATTRIBUTE;
+bound return IDL_BOUND;
+case return IDL_CASE;
+const return IDL_CONST;
+constants return IDL_CONSTANTS;
+constrained return IDL_CONSTRAINED;
+default return IDL_DEFAULT;
+enum return IDL_ENUM;
+exception return IDL_EXCEPTION;
+interface return IDL_INTERFACE;
+maybeambiguous return IDL_MAYBEAMBIGUOUS;
+maybedefault return IDL_MAYBEDEFAULT;
+maybevoid return IDL_MAYBEVOID;
+module return IDL_MODULE;
+needs return IDL_NEEDS;
+observes return IDL_OBSERVES;
+optional return IDL_OPTIONAL;
+property return IDL_PROPERTY;
+raises return IDL_RAISES;
+readonly return IDL_READONLY;
+removable return IDL_REMOVEABLE;
+service return IDL_SERVICE;
+sequence return IDL_SEQUENCE;
+struct return IDL_STRUCT;
+switch return IDL_SWITCH;
+transient return IDL_TRANSIENT;
+typedef return IDL_TYPEDEF;
+union return IDL_UNION;
+
+any return IDL_ANY;
+boolean return IDL_BOOLEAN;
+byte return IDL_BYTE;
+char return IDL_CHAR;
+double return IDL_DOUBLE;
+float return IDL_FLOAT;
+hyper return IDL_HYPER;
+long return IDL_LONG;
+short return IDL_SHORT;
+string return IDL_STRING;
+type return IDL_TYPE;
+unsigned return IDL_UNSIGNED;
+void return IDL_VOID;
+
+TRUE return IDL_TRUE;
+True return IDL_TRUE;
+FALSE return IDL_FALSE;
+False return IDL_FALSE;
+
+in return IDL_IN;
+out return IDL_OUT;
+inout return IDL_INOUT;
+oneway return IDL_ONEWAY;
+
+("-")?{INT_LITERAL}+(l|L|u|U)? {
+ yylval.ival = asciiToInteger( 10, yytext );
+ return IDL_INTEGER_LITERAL;
+ }
+
+("-")?{OCT_LITERAL}+(l|L|u|U)? {
+ yylval.ival = asciiToInteger( 8, yytext+1 );
+ return IDL_INTEGER_LITERAL;
+ }
+
+("-")?{HEX_LITERAL}+(l|L|u|U)? {
+ yylval.ival = asciiToInteger( 16, yytext+2 );
+ return IDL_INTEGER_LITERAL;
+ }
+
+{CHAR_LITERAL} {
+ yylval.cval = *yytext;
+ return IDL_CHARACTER_LITERAL;
+ }
+
+{STRING_LITERAL} {
+ yylval.sval = new ::rtl::OString(yytext);
+ return IDL_STRING_LITERAL;
+ }
+
+("-")?{DIGIT}*(e|E){1}(("+"|"-")?{DIGIT}+)+(f|F)? |
+("-")?"."{DIGIT}*((e|E)("+"|"-")?{DIGIT}+)?(f|F)? |
+("-")?{DIGIT}*"."{DIGIT}*((e|E)("+"|"-")?{DIGIT}+)?(f|F)? {
+ yylval.dval = asciiToFloat( yytext );
+ return IDL_FLOATING_PT_LITERAL;
+ }
+
+{IDENTIFIER} {
+ yylval.sval = new ::rtl::OString(yytext);
+ return IDL_IDENTIFIER;
+ }
+
+\<\< {
+ yylval.strval = yytext;
+ return IDL_LEFTSHIFT;
+ }
+\>\> {
+ yylval.strval = yytext;
+ return IDL_RIGHTSHIFT;
+ }
+\:\: {
+ yylval.strval = yytext;
+ return IDL_SCOPESEPERATOR;
+ }
+
+"/*" {
+ BEGIN( COMMENT );
+ docu = ::rtl::OString();
+ beginLine = idlc()->getLineNumber();
+ }
+
+"/***" {
+ BEGIN( COMMENT );
+ docu = ::rtl::OString();
+ beginLine = idlc()->getLineNumber();
+ }
+
+<COMMENT>[^*]+ {
+ docu += ::rtl::OString(yytext);
+ }
+
+<COMMENT>"*"[^*/]+ {
+ docu += ::rtl::OString(yytext);
+ }
+
+<COMMENT>"**" {
+ docu += ::rtl::OString(yytext);
+ }
+
+<COMMENT>[*]+"/" {
+ docu = docu.trim();
+ idlc()->setLineNumber( beginLine + docu.getTokenCount('\n') - 1);
+ BEGIN( INITIAL );
+ }
+
+"/**" {
+ BEGIN( DOCU );
+ docu = ::rtl::OString();
+ beginLine = idlc()->getLineNumber();
+ }
+
+<DOCU>[^*\n]+ {
+ docu += ::rtl::OString(yytext);
+ }
+<DOCU>"\n"[ \t]*"*"{1} {
+ docu += ::rtl::OString("\n");
+ }
+
+<DOCU>"\n" {
+ docu += ::rtl::OString(yytext);
+ }
+
+<DOCU>"*"[^*/\n]+ {
+ docu += ::rtl::OString(yytext);
+ }
+
+<DOCU>"\n"[ \t]*"*/" {
+ docu = docu.trim();
+ idlc()->setLineNumber( beginLine + docu.getTokenCount('\n') - 1);
+ idlc()->setDocumentation(docu);
+ BEGIN( INITIAL );
+ }
+
+<DOCU>"*/" {
+ docu = docu.trim();
+ idlc()->setLineNumber( beginLine + docu.getTokenCount('\n') - 1);
+ idlc()->setDocumentation(docu);
+ BEGIN( INITIAL );
+ }
+
+"//"[^/]{1}.*"\n" {
+ /* only a comment */
+ ::rtl::OString docStr(yytext);
+ docStr = docStr.copy( 0, docStr.lastIndexOf('\n') );
+ docStr = docStr.copy( docStr.lastIndexOf('/')+1 );
+ docStr = docStr.trim();
+ idlc()->incLineNumber();
+ }
+
+"///".*"\n" {
+ ::rtl::OString docStr(yytext);
+ docStr = docStr.copy( 0, docStr.lastIndexOf('\n') );
+ docStr = docStr.copy( docStr.lastIndexOf('/')+1 );
+ docStr = docStr.trim();
+ idlc()->incLineNumber();
+ idlc()->setDocumentation(docStr);
+ }
+
+. return yytext[0];
+
+^#[ \t]*line[ \t]*[0-9]*" ""\""[^\"]*"\""\n {
+ parseLineAndFile(yytext);
+}
+
+^#[ \t]*[0-9]*" ""\""[^\"]*"\""" "[0-9]*\n {
+ parseLineAndFile(yytext);
+}
+
+^#[ \t]*[0-9]*" ""\""[^\"]*"\""\n {
+ parseLineAndFile(yytext);
+}
+
+^#[ \t]*[0-9]*\n {
+ parseLineAndFile(yytext);
+}
+
+^#[ \t]*ident.*\n {
+ /* ignore cpp ident */
+ idlc()->incLineNumber();
+}
+
+^#[ \t]*pragma[ \t].*\n { /* remember pragma */
+ idlParsePragma(yytext);
+ idlc()->incLineNumber();
+}
+
+%%