This commit is contained in:
dario 1998-05-12 20:30:45 +00:00
Родитель 5ae326ef3a
Коммит 3d129f2914
25 изменённых файлов: 3914 добавлений и 0 удалений

89
dom/tools/Exceptions.cpp Normal file
Просмотреть файл

@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "Exceptions.h"
#include <stdlib.h>
#include <string.h>
#include <ostream.h>
ostream& operator<<(ostream &s, Exception &e)
{
return s << e.GetMessage() << '\n';
}
Exception::Exception()
{
mMessage = (char*)0;
}
Exception::Exception(const char *aMessage)
{
size_t size = strlen(aMessage) + 1;
mMessage = new char[size];
strcpy(mMessage, aMessage);
}
Exception::~Exception()
{
if (mMessage) {
delete[] mMessage;
}
}
Exception::Exception(Exception &aException)
{
size_t size = strlen(aException.mMessage) + 1;
mMessage = new char[size];
strcpy(mMessage, aException.mMessage);
}
void Exception::SetMessage(char *aMessage)
{
if (mMessage) {
delete[] mMessage;
mMessage = (char*)0;
}
if (aMessage) {
size_t size = strlen(aMessage) + 1;
mMessage = new char[size];
strcpy(mMessage, aMessage);
}
}
char* Exception::GetMessage()
{
return mMessage;
}
AbortParser::AbortParser(char *aFileName, long aLineNumber)
{
char message[512]; // seems big enough
char lineNumber[20];
strcpy(message, "File: ");
strcat(message, aFileName);
strcat(message, ". Line Number: ");
itoa(aLineNumber, lineNumber, 10);
strcat(message, lineNumber);
SetMessage(message);
}

111
dom/tools/Exceptions.h Normal file
Просмотреть файл

@ -0,0 +1,111 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _Exception_h__
#define _Exception_h__
class Exception
{
private:
char *mMessage;
public:
Exception();
Exception(const char *aMessage);
Exception(Exception &aException);
~Exception();
void SetMessage(char *aMessage);
char* GetMessage();
};
class NotImplementedException : public Exception
{
public:
NotImplementedException() : Exception("Function not yet implemented.") {}
~NotImplementedException() {}
};
class AbortParser : public Exception
{
public:
AbortParser(char *aFileName, long aLineNumber);
~AbortParser() {}
};
class ParserException : public Exception
{
public:
ParserException(char *aMessage) : Exception(aMessage) {}
~ParserException() {}
};
class InterfaceParsingException : public ParserException
{
public:
InterfaceParsingException(char *aMessage) : ParserException(aMessage) {}
~InterfaceParsingException() {}
};
class EnumParsingException : public ParserException
{
public:
EnumParsingException(char *aMessage) : ParserException(aMessage) {}
~EnumParsingException() {}
};
class AttributeParsingException : public ParserException
{
public:
AttributeParsingException(char *aMessage) : ParserException(aMessage) {}
~AttributeParsingException() {}
};
class FunctionParsingException : public ParserException
{
public:
FunctionParsingException(char *aMessage) : ParserException(aMessage) {}
~FunctionParsingException() {}
};
class ParameterParsingException : public ParserException
{
public:
ParameterParsingException(char *aMessage) : ParserException(aMessage) {}
~ParameterParsingException() {}
};
class EndOfFileException : public Exception
{
public:
EndOfFileException(char *aMessage) : Exception(aMessage) {}
~EndOfFileException() {}
};
class ScannerUnknownCharacter : public Exception
{
public:
ScannerUnknownCharacter(char *aMessage) : Exception(aMessage) {}
~ScannerUnknownCharacter() {}
};
class ostream;
ostream& operator<<(ostream &s, Exception &e);
#endif

Просмотреть файл

@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "IdlAttribute.h"
IdlAttribute::IdlAttribute()
{
mReadOnly = 0;
}
IdlAttribute::~IdlAttribute()
{
}
void IdlAttribute::SetReadOnly(int aReadOnlyFlag)
{
mReadOnly = aReadOnlyFlag;
}
int IdlAttribute::GetReadOnly()
{
return mReadOnly;
}

39
dom/tools/IdlAttribute.h Normal file
Просмотреть файл

@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlAttribute_h__
#define _IdlAttribute_h__
#include "IdlVariable.h"
class IdlAttribute : public IdlVariable {
private:
int mReadOnly;
public:
IdlAttribute();
~IdlAttribute();
void SetReadOnly(int aReadOnlyFlag);
int GetReadOnly();
};
#endif

64
dom/tools/IdlEnum.cpp Normal file
Просмотреть файл

@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "IdlEnum.h"
#include "nsVoidArray.h"
#include "IdlVariable.h"
IdlEnum::IdlEnum()
{
mEnumerators = (nsVoidArray*)0;
}
IdlEnum::~IdlEnum()
{
if (mEnumerators) {
for (int i = 0; i < mEnumerators->Count(); i++) {
IdlVariable *varObj = (IdlVariable*)mEnumerators->ElementAt(i);
delete varObj;
}
}
}
void IdlEnum::AddEnumerator(IdlVariable *aEnumerator)
{
if (aEnumerator) {
if (!mEnumerators) {
mEnumerators = new nsVoidArray();
}
mEnumerators->AppendElement((void*)aEnumerator);
}
}
long IdlEnum::EnumeratorCount()
{
if (mEnumerators) {
return mEnumerators->Count();
}
return 0;
}
IdlVariable* IdlEnum::GetEnumeratorAt(long aIndex)
{
IdlVariable *varObj = (IdlVariable*)0;
if (mEnumerators) {
varObj = (IdlVariable*)mEnumerators->ElementAt(aIndex);
}
return varObj;
}

41
dom/tools/IdlEnum.h Normal file
Просмотреть файл

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlEnum_h__
#define _IdlEnum_h__
#include "IdlObject.h"
class IdlVariable;
class nsVoidArray;
class IdlEnum : public IdlObject {
private:
nsVoidArray *mEnumerators;
public:
IdlEnum();
~IdlEnum();
void AddEnumerator(IdlVariable *aEnumerator);
long EnumeratorCount();
IdlVariable* GetEnumeratorAt(long aIndex);
};
#endif

124
dom/tools/IdlFunction.cpp Normal file
Просмотреть файл

@ -0,0 +1,124 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "IdlFunction.h"
#include "IdlObject.h"
#include "nsVoidArray.h"
#include "IdlParameter.h"
IdlFunction::IdlFunction()
{
mReturnValue = (IdlVariable*)0;
mParameters = (nsVoidArray*)0;
mExceptions = (nsVoidArray*)0;
}
IdlFunction::~IdlFunction()
{
if (mReturnValue) {
delete mReturnValue;
}
if (mParameters) {
for (int i = 0; i < mParameters->Count(); i++) {
IdlParameter *paramObj = (IdlParameter*)mParameters->ElementAt(i);
delete paramObj;
}
}
if (mExceptions) {
for (int i = 0; i < mExceptions->Count(); i++) {
IdlException *excObj = (IdlException*)mExceptions->ElementAt(i);
delete excObj;
}
}
}
void IdlFunction::SetReturnValue(Type aType, char *aTypeName)
{
if (mReturnValue) {
delete mReturnValue;
}
mReturnValue = new IdlVariable();
mReturnValue->SetType(aType);
if (aTypeName) {
mReturnValue->SetTypeName(aTypeName);
}
}
IdlVariable* IdlFunction::GetReturnValue()
{
return mReturnValue;
}
void IdlFunction::AddParameter(IdlParameter *aParameter)
{
if (aParameter) {
if (!mParameters) {
mParameters = new nsVoidArray();
}
mParameters->AppendElement((void*)aParameter);
}
}
long IdlFunction::ParameterCount()
{
if (mParameters) {
return mParameters->Count();
}
return 0;
}
IdlParameter* IdlFunction::GetParameterAt(long aIndex)
{
IdlParameter *paramObj = (IdlParameter*)0;
if (mParameters) {
paramObj = (IdlParameter*)mParameters->ElementAt(aIndex);
}
return paramObj;
}
void IdlFunction::AddException(char *aException)
{
if (aException) {
if (!mExceptions) {
mExceptions = new nsVoidArray();
}
mExceptions->AppendElement((void*)aException);
}
}
long IdlFunction::ExceptionCount()
{
if (mExceptions) {
return mExceptions->Count();
}
return 0;
}
char* IdlFunction::GetExceptionAt(long aIndex)
{
char *excName = (char*)0;
if (mExceptions) {
excName = (char*)mExceptions->ElementAt(aIndex);
}
return excName;
}

52
dom/tools/IdlFunction.h Normal file
Просмотреть файл

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlFunction_h__
#define _IdlFunction_h__
#include "IdlObject.h"
#include "IdlVariable.h"
class nsVoidArray;
class IdlParameter;
class IdlFunction : public IdlObject {
private:
IdlVariable *mReturnValue;
nsVoidArray *mParameters;
nsVoidArray *mExceptions;
public:
IdlFunction();
~IdlFunction();
void SetReturnValue(Type aType, char *aTypeName = (char*)0);
IdlVariable* GetReturnValue();
void AddParameter(IdlParameter *aParameter);
long ParameterCount();
IdlParameter* GetParameterAt(long aIndex);
void AddException(char *aException);
long ExceptionCount();
char* GetExceptionAt(long aIndex);
};
#endif

348
dom/tools/IdlInterface.cpp Normal file
Просмотреть файл

@ -0,0 +1,348 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "IdlInterface.h"
#include "nsVoidArray.h"
#include "IdlEnum.h"
#include "IdlAttribute.h"
#include "IdlFunction.h"
#include <string.h>
IdlInterface::IdlInterface()
{
mBaseClasses = (nsVoidArray*)0;
mAttributes = (nsVoidArray*)0;
mFunctions = (nsVoidArray*)0;
mEnums = (nsVoidArray*)0;
mStructs = (nsVoidArray*)0;
mUnions = (nsVoidArray*)0;
mConsts = (nsVoidArray*)0;
mTypedefs = (nsVoidArray*)0;
mExceptions = (nsVoidArray*)0;
}
IdlInterface::~IdlInterface()
{
if (mBaseClasses) {
for (int i = 0; i < mBaseClasses->Count(); i++) {
char *baseClass = (char*)mBaseClasses->ElementAt(i);
delete[] baseClass;
}
}
if (mAttributes) {
for (int i = 0; i < mAttributes->Count(); i++) {
IdlAttribute *attrObj = (IdlAttribute*)mAttributes->ElementAt(i);
delete attrObj;
}
}
if (mFunctions) {
for (int i = 0; i < mFunctions->Count(); i++) {
IdlFunction *funcObj = (IdlFunction*)mFunctions->ElementAt(i);
delete funcObj;
}
}
if (mEnums) {
for (int i = 0; i < mEnums->Count(); i++) {
IdlEnum *enumObj = (IdlEnum*)mEnums->ElementAt(i);
delete enumObj;
}
}
if (mStructs) {
for (int i = 0; i < mStructs->Count(); i++) {
IdlStruct *structObj = (IdlStruct*)mStructs->ElementAt(i);
delete structObj;
}
}
if (mUnions) {
for (int i = 0; i < mUnions->Count(); i++) {
IdlUnion *unionObj = (IdlUnion*)mUnions->ElementAt(i);
delete unionObj;
}
}
if (mConsts) {
for (int i = 0; i < mConsts->Count(); i++) {
IdlConst *constObj = (IdlConst*)mConsts->ElementAt(i);
delete constObj;
}
}
if (mTypedefs) {
for (int i = 0; i < mTypedefs->Count(); i++) {
IdlTypedef *typedefObj = (IdlTypedef*)mTypedefs->ElementAt(i);
delete typedefObj;
}
}
if (mExceptions) {
for (int i = 0; i < mExceptions->Count(); i++) {
IdlException *exceptionObj = (IdlException*)mExceptions->ElementAt(i);
delete exceptionObj;
}
}
}
void IdlInterface::InheritsFrom(char *aBase)
{
if (aBase) {
size_t length = strlen(aBase) + 1;
char *baseName = new char[length];
strcpy(baseName, aBase);
if (!mBaseClasses) {
mBaseClasses = new nsVoidArray();
}
mBaseClasses->AppendElement((void*)baseName);
}
}
long IdlInterface::BaseClasseCount()
{
if (mBaseClasses) {
return mBaseClasses->Count();
}
return 0;
}
char* IdlInterface::GetBaseClassAt(long aIndex)
{
char *base = (char*)0;
if (mBaseClasses) {
base = (char*)mBaseClasses->ElementAt(aIndex);
}
return base;
}
void IdlInterface::AddTypedef(IdlTypedef *aTypedef)
{
if (aTypedef) {
if (!mTypedefs) {
mTypedefs = new nsVoidArray();
}
mTypedefs->AppendElement((void*)aTypedef);
}
}
long IdlInterface::TypedefCount()
{
if (mTypedefs) {
return mTypedefs->Count();
}
return 0;
}
IdlTypedef* IdlInterface::GetTypedefAt(long aIndex)
{
IdlTypedef *typedefObj = (IdlTypedef*)0;
if (mTypedefs) {
typedefObj = (IdlTypedef*)mTypedefs->ElementAt(aIndex);
}
return typedefObj;
}
void IdlInterface::AddStruct(IdlStruct *aStruct)
{
if (aStruct) {
if (!mStructs) {
mStructs = new nsVoidArray();
}
mStructs->AppendElement((void*)aStruct);
}
}
long IdlInterface::StructCount()
{
if (mStructs) {
return mStructs->Count();
}
return 0;
}
IdlStruct* IdlInterface::GetStructAt(long aIndex)
{
IdlStruct *structObj = (IdlStruct*)0;
if (mStructs) {
structObj = (IdlStruct*)mStructs->ElementAt(aIndex);
}
return structObj;
}
void IdlInterface::AddEnum(IdlEnum *aEnum)
{
if (aEnum) {
if (!mEnums) {
mEnums = new nsVoidArray();
}
mEnums->AppendElement((void*)aEnum);
}
}
long IdlInterface::EnumCount()
{
if (mEnums) {
return mEnums->Count();
}
return 0;
}
IdlEnum* IdlInterface::GetEnumAt(long aIndex)
{
IdlEnum *enumObj = (IdlEnum*)0;
if (mEnums) {
enumObj = (IdlEnum*)mEnums->ElementAt(aIndex);
}
return enumObj;
}
void IdlInterface::AddUnion(IdlUnion *aUnion)
{
if (aUnion) {
if (!mUnions) {
mUnions = new nsVoidArray();
}
mUnions->AppendElement((void*)aUnion);
}
}
long IdlInterface::UnionCount()
{
if (mUnions) {
return mUnions->Count();
}
return 0;
}
IdlUnion* IdlInterface::GetUnionAt(long aIndex)
{
IdlUnion *unionObj = (IdlUnion*)0;
if (mUnions) {
unionObj = (IdlUnion*)mUnions->ElementAt(aIndex);
}
return unionObj;
}
void IdlInterface::AddConst(IdlConst *aConst)
{
if (aConst) {
if (!mConsts) {
mConsts = new nsVoidArray();
}
mConsts->AppendElement((void*)aConst);
}
}
long IdlInterface::ConstCount()
{
if (mConsts) {
return mConsts->Count();
}
return 0;
}
IdlConst* IdlInterface::GetConstAt(long aIndex)
{
IdlConst *constObj = (IdlConst*)0;
if (mConsts) {
constObj = (IdlConst*)mConsts->ElementAt(aIndex);
}
return constObj;
}
void IdlInterface::AddException(IdlException *aException)
{
if (aException) {
if (!mExceptions) {
mExceptions = new nsVoidArray();
}
mExceptions->AppendElement((void*)aException);
}
}
long IdlInterface::ExceptionCount()
{
if (mExceptions) {
return mExceptions->Count();
}
return 0;
}
IdlException* IdlInterface::GetExceptionAt(long aIndex)
{
IdlException *excObj = (IdlException*)0;
if (mExceptions) {
excObj = (IdlException*)mExceptions->ElementAt(aIndex);
}
return excObj;
}
void IdlInterface::AddAttribute(IdlAttribute *aAttribute)
{
if (aAttribute) {
if (!mAttributes) {
mAttributes = new nsVoidArray();
}
mAttributes->AppendElement((void*)aAttribute);
}
}
long IdlInterface::AttributeCount()
{
if (mAttributes) {
return mAttributes->Count();
}
return 0;
}
IdlAttribute* IdlInterface::GetAttributeAt(long aIndex)
{
IdlAttribute *attrObj = (IdlAttribute*)0;
if (mAttributes) {
attrObj = (IdlAttribute*)mAttributes->ElementAt(aIndex);
}
return attrObj;
}
void IdlInterface::AddFunction(IdlFunction *aFunction)
{
if (aFunction) {
if (!mFunctions) {
mFunctions = new nsVoidArray();
}
mFunctions->AppendElement((void*)aFunction);
}
}
long IdlInterface::FunctionCount()
{
if (mFunctions) {
return mFunctions->Count();
}
return 0;
}
IdlFunction* IdlInterface::GetFunctionAt(long aIndex)
{
IdlFunction *funcObj = (IdlFunction*)0;
if (mFunctions) {
funcObj = (IdlFunction*)mFunctions->ElementAt(aIndex);
}
return funcObj;
}

81
dom/tools/IdlInterface.h Normal file
Просмотреть файл

@ -0,0 +1,81 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlInterface_h__
#define _IdlInterface_h__
#include "IdlObject.h"
class nsVoidArray;
class IdlTypedef;
class IdlStruct;
class IdlUnion;
class IdlEnum;
class IdlAttribute;
class IdlFunction;
class IdlConst;
class IdlException;
class IdlInterface : public IdlObject {
private:
nsVoidArray *mBaseClasses;
nsVoidArray *mAttributes;
nsVoidArray *mFunctions;
nsVoidArray *mEnums;
nsVoidArray *mStructs;
nsVoidArray *mUnions;
nsVoidArray *mConsts;
nsVoidArray *mTypedefs;
nsVoidArray *mExceptions;
public:
IdlInterface();
~IdlInterface();
void InheritsFrom(char *aBase);
long BaseClasseCount();
char* GetBaseClassAt(long aIndex);
void AddTypedef(IdlTypedef *aTypedef);
long TypedefCount();
IdlTypedef* GetTypedefAt(long aIndex);
void AddStruct(IdlStruct *aStruct);
long StructCount();
IdlStruct* GetStructAt(long aIndex);
void AddEnum(IdlEnum *aEnum);
long EnumCount();
IdlEnum* GetEnumAt(long aIndex);
void AddUnion(IdlUnion *aUnion);
long UnionCount();
IdlUnion* GetUnionAt(long aIndex);
void AddConst(IdlConst *aConst);
long ConstCount();
IdlConst* GetConstAt(long aIndex);
void AddException(IdlException *aException);
long ExceptionCount();
IdlException* GetExceptionAt(long aIndex);
void AddAttribute(IdlAttribute *aAttribute);
long AttributeCount();
IdlAttribute* GetAttributeAt(long aIndex);
void AddFunction(IdlFunction *aFunction);
long FunctionCount();
IdlFunction* GetFunctionAt(long aIndex);
};
#endif

55
dom/tools/IdlObject.cpp Normal file
Просмотреть файл

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "IdlObject.h"
#include <string.h>
IdlObject::IdlObject()
{
mName = (char*)0;
}
IdlObject::~IdlObject()
{
if (mName) {
delete[] mName;
}
}
char* IdlObject::GetName()
{
return mName;
}
void IdlObject::SetName(char *aName)
{
if (mName) {
delete[] mName;
mName = (char*)0;
}
if (aName) {
size_t length = ::strlen(aName) + 1;
mName = new char[length];
strcpy(mName, aName);
}
}

42
dom/tools/IdlObject.h Normal file
Просмотреть файл

@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlObject_h__
#define _IdlObject_h__
class IdlObject {
private:
char *mName;
public:
IdlObject();
~IdlObject();
char* GetName();
void SetName(char *aName);
};
#define IdlTypedef IdlObject
#define IdlStruct IdlObject
#define IdlUnion IdlObject
#define IdlConst IdlObject
#define IdlException IdlObject
#endif

Просмотреть файл

@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "IdlParameter.h"
IdlParameter::IdlParameter()
{
mAttribute = 0;
}
IdlParameter::~IdlParameter()
{
}
void IdlParameter::SetAttribute(CallAttribute aAttribute)
{
mAttribute = aAttribute;
}
int IdlParameter::GetAttribute()
{
return mAttribute;
}

46
dom/tools/IdlParameter.h Normal file
Просмотреть файл

@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlParameter_h__
#define _IdlParameter_h__
#include "IdlVariable.h"
class IdlParameter : public IdlVariable {
public:
enum CallAttribute {
INPUT = 0,
OUTPUT,
INOUT
};
private:
int mAttribute;
public:
IdlParameter();
~IdlParameter();
void SetAttribute(CallAttribute aAttribute);
int GetAttribute();
};
#endif

760
dom/tools/IdlParser.cpp Normal file
Просмотреть файл

@ -0,0 +1,760 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/**
IDL syntax
specification = definition < specification > .
definition = ( type_dcl / const_dcl / except_dcl / interface / module ) ";" .
interface = interface_dcl / forward_dcl .
forward_dcl = "interface" identifier .
interface_dcl = interface_header "{" interface_body "}" .
interface_header = "interface" identifier [ inheritance_spec ] .
interface_body = < export > .
export = ( type_dcl / const_dcl / except_dcl / attr_dcl / op_dcl ) ";" .
inheritance_spec = ":" scoped_name < "," scoped_name > .
scoped_name = identifier
/ ( "::" identifier )
/ ( scoped_name "::" identifier ) .
*/
// initialize cout
#include <ostream.h>
#include "IdlParser.h"
#include "IdlScanner.h"
#include "Exceptions.h"
#include "IdlSpecification.h"
#include "IdlInterface.h"
#include "IdlEnum.h"
#include "IdlVariable.h"
#include "IdlAttribute.h"
#include "IdlFunction.h"
#include "IdlParameter.h"
// not defined yet. We don't need this types for now
// so the forward declaration in IdlParser.h is good enough
/*
#include "IdlTypedef.h"
#include "IdlStruct.h"
#include "IdlUnion.h"
#include "IdlConst.h"
#include "IdlException.h"
*/
/**
* constructor
*/
IdlParser::IdlParser()
{
mScanner = new IdlScanner();
}
/**
* destructor
*/
IdlParser::~IdlParser()
{
if (mScanner) {
delete mScanner;
}
}
/**
* specification = definition < specification > .
* definition = ( type_dcl / const_dcl / except_dcl / interface / module ) ";" .
*
* We only understand interfaces so go directly to process interfaces.
* A more complex parsing of specification requires changes in this method
* (or subclassing if you like and you can let this class process the interfaces only)
*/
void IdlParser::Parse(char *aFileName, IdlSpecification &aSpecification)
{
// connect the scanner to the file in input
if (mScanner->Open(aFileName)) {
try {
// read all the interfaces in the idl file
IdlInterface *idlInterface;
while (mScanner->CanReadMoreData()) {
idlInterface = ParseInterface(aSpecification);
if (idlInterface)
aSpecification.AddInterface(idlInterface);
}
} catch (ParserException &exc) {
cout << exc;
throw AbortParser(mScanner->GetFileName(), mScanner->GetLineNumber());
}
}
}
/**
* interface = interface_dcl / forward_dcl
* forward_dcl = "interface" identifier
* interface_dcl = interface_header "{" interface_body "}"
* interface_header = "interface" identifier [ inheritance_spec ]
* interface_body = < export >
*
* We look for
* "interface" identifier
* and if followed by "{" or ":" we expect a full interface declaration
* otherwise it is just a forward declaration
*
*/
IdlInterface* IdlParser::ParseInterface(IdlSpecification &aSpecification)
{
IdlInterface *interfaceObj = (IdlInterface*)0;
// go through all comments and assume the last one is a comment for the
// interface
Token *token = (Token*)0;
while (mScanner->CanReadMoreData() && COMMENT_TOKEN == mScanner->PeekToken()->id) {
token = mScanner->NextToken();
}
if (token) {
//XXX save last comment somewhere...
}
if (mScanner->CanReadMoreData()) {
try {
// must be "interface" identifier
if (INTERFACE_TOKEN == mScanner->NextToken()->id) {
TrimComments();
token = mScanner->NextToken();
if (IDENTIFIER_TOKEN == token->id) {
interfaceObj = new IdlInterface();
interfaceObj->SetName(token->stringID);
}
else {
throw InterfaceParsingException("Missing identifier. Interface name undefined.");
}
}
else {
throw InterfaceParsingException("Interface expected. We only process interfaces specification.");
}
TrimComments();
// look for ":"
int inheritanceSpec = 0;
token = mScanner->PeekToken();
if (INHERITANCE_SPEC_TOKEN == token->id) {
mScanner->NextToken(); // read ":"
TrimComments();
//XXX we deal only with an interface_header structured as follow
// interface_header = ":" identifier < "," identifier >
token = mScanner->NextToken(); // this must be the base class
while (IDENTIFIER_TOKEN == token->id) {
interfaceObj->InheritsFrom(token->stringID);
TrimComments();
token = mScanner->PeekToken();
if (SEPARATOR_TOKEN == token->id) {
mScanner->NextToken(); // eat ","
TrimComments();
token = mScanner->NextToken(); // this must be the next base class
}
else {
// next token isn't a ","
// we are done with interface_header
inheritanceSpec = 1;
break;
}
}
if (0 == inheritanceSpec) {
delete interfaceObj;
throw InterfaceParsingException("Bad inheritance specification.");
}
}
// got a "{"
if (BEGIN_BLOCK_TOKEN == token->id) {
ParseInterfaceBody(aSpecification, *interfaceObj);
}
else if (inheritanceSpec) {
delete interfaceObj;
// if interface_header was found a interface_body must be defined
throw InterfaceParsingException("Missing interface body.");
}
else {
//XXX it's a forward declaration what do we do?
}
} catch (EndOfFileException &) {
if (interfaceObj != 0) {
delete interfaceObj;
}
// unexpected end of file. Trying to read after a EOF has
// been returned
throw ParserException("Unexpected End of File.");
}
// read the final ";"
token = mScanner->NextToken();
if (TERMINATOR_TOKEN != token->id) {
throw InterfaceParsingException("Missing ';'.");
}
}
return interfaceObj;
}
/**
* interface_body = < export >
* export = ( type_dcl / const_dcl / except_dcl / attr_dcl / op_dcl ) ";"
* type_dcl = "typedef" type_declarator
* / struct_type
* / union_type
* / enum_type
* struct_type = "struct" identifier "{" member_list "}"
* union_type = "union" identifier "switch" "(" switch_type_spec ")"
* "{" switch_body "}"
* enum_type = "enum" identifier "{" enumerator < "," enumerator > "}"
* const_dcl = "const" const_type identifier "=" const_exp
* except_dcl = "exception" identifier "{" < member > "}"
* attr_dcl = [ "readonly" ] "attribute" param_type_spec identifier
* op_dcl = [ op_attribute ] op_type_spec identifier parameter_dcls
* [ raises_expr ] [ context_expr ]
* op_attribute = "oneway" .
* op_type_spec = param_type_spec / "void"
* param_type_spec = base_type_spec / string_type / scoped_name
* base_type_spec = floating_pt_type
* / integer_type
* / char_type
* / boolean_type
* / octet_type
* / any_type
* scoped_name = identifier
* / ( "::" identifier )
* / ( scoped_name "::" identifier )
*/
void IdlParser::ParseInterfaceBody(IdlSpecification &aSpecification, IdlInterface &aInterface)
{
// eat "{"
mScanner->NextToken();
TrimComments();
// untill "}" parse the interface body
Token *token = (Token*)0;
while (END_BLOCK_TOKEN != mScanner->PeekToken()->id) {
token = mScanner->NextToken();
TrimComments();
// parse the proper valid type
switch (token->id) {
case TYPEDEF_TOKEN:
aInterface.AddTypedef(ParseTypedef(aSpecification));
break;
case STRUCT_TOKEN:
aInterface.AddStruct(ParseStruct(aSpecification));
break;
case ENUM_TOKEN:
aInterface.AddEnum(ParseEnum(aSpecification));
break;
case UNION_TOKEN:
aInterface.AddUnion(ParseUnion(aSpecification));
break;
case CONST_TOKEN:
aInterface.AddConst(ParseConst(aSpecification));
break;
case EXCEPTION_TOKEN:
aInterface.AddException(ParseException(aSpecification));
break;
case READONLY_TOKEN:
case ATTRIBUTE_TOKEN:
aInterface.AddAttribute(ParseAttribute(aSpecification, token->id));
break;
default:
// it's either a function or an error
aInterface.AddFunction(ParseFunction(aSpecification, *token));
break;
}
TrimComments();
// read the final ";"
token = mScanner->NextToken();
if (TERMINATOR_TOKEN != token->id) {
throw InterfaceParsingException("Missing ';'.");
}
}
// eat "}"
mScanner->NextToken();
}
/**
* XXX NOT IMPLEMENTED YET
*/
IdlTypedef* IdlParser::ParseTypedef(IdlSpecification &aSpecification)
{
throw NotImplementedException();
return (IdlTypedef*)0;
}
/**
* XXX NOT IMPLEMENTED YET
*/
IdlStruct* IdlParser::ParseStruct(IdlSpecification &aSpecification)
{
throw NotImplementedException();
return (IdlStruct*)0;
}
/**
* enum_type = "enum" identifier "{" enumerator < "," enumerator > "}"
* enumerator = identifier
*
* We semplify enum's and define them as
* enum_type = "enum" identifier "{" enumerator < "," integer_literal > "}"
* enumerator = identifier
*/
IdlEnum* IdlParser::ParseEnum(IdlSpecification &aSpecification)
{
IdlEnum *enumObj = new IdlEnum();
Token *token;
// can be an identifier
token = mScanner->NextToken();
if (IDENTIFIER_TOKEN == token->id) {
enumObj->SetName(token->stringID);
TrimComments();
token = mScanner->NextToken();
}
// a "{" must be present anyway
if (BEGIN_BLOCK_TOKEN == token->id) {
// untill "}" parse the enum
token = mScanner->PeekToken();
while (END_BLOCK_TOKEN != token->id) {
// must be an identifier
if (IDENTIFIER_TOKEN == token->id) {
IdlVariable* enumerator = new IdlVariable();
enumerator->SetType(TYPE_INT); // it does not really matter
enumerator->SetName(mScanner->NextToken()->stringID);
enumObj->AddEnumerator(enumerator);
TrimComments();
// if "=" is specified an integer must follow
// NOTE: this is an ad hoc solution for the w3c dom. Enum can
// be more complex than this
token = mScanner->PeekToken();
if (ASSIGNEMENT_TOKEN == token->id) {
mScanner->NextToken(); // eat "="
TrimComments();
// must be an integer
token = mScanner->NextToken();
if (token->id == INTEGER_CONSTANT) {
enumerator->SetValue(token->value.vLong);
TrimComments();
token = mScanner->PeekToken();
}
else {
delete enumObj;
throw EnumParsingException("The specified enumerator value is not an integer.");
}
}
if (SEPARATOR_TOKEN == token->id) {
mScanner->NextToken(); // eat ","
TrimComments();
token = mScanner->PeekToken();
}
}
else {
delete enumObj;
throw EnumParsingException("Missing identifier in enum body.");
}
}
mScanner->NextToken(); // eat "}"
}
else {
delete enumObj;
throw EnumParsingException("Missing enum body.");
}
return enumObj;
}
/**
* XXX NOT IMPLEMENTED YET
*/
IdlUnion* IdlParser::ParseUnion(IdlSpecification &aSpecification)
{
throw NotImplementedException();
return (IdlUnion*)0;
}
/**
* XXX NOT IMPLEMENTED YET
*/
IdlConst* IdlParser::ParseConst(IdlSpecification &aSpecification)
{
throw NotImplementedException();
return (IdlConst*)0;
}
/**
* XXX NOT IMPLEMENTED YET
*/
IdlException* IdlParser::ParseException(IdlSpecification &aSpecification)
{
throw NotImplementedException();
return (IdlException*)0;
}
/**
* attr_dcl = [ "readonly" ] "attribute" param_type_spec identifier
* param_type_spec = base_type_spec / string_type / scoped_name
*/
IdlAttribute* IdlParser::ParseAttribute(IdlSpecification &aSpecification, int aTokenID)
{
Token *token;
int isReadOnly = 0;
// if it was a readonly keyword read the attribute keyword
if (READONLY_TOKEN == aTokenID) {
isReadOnly = 1;
TrimComments();
token = mScanner->NextToken();
if (ATTRIBUTE_TOKEN != token->id) {
throw AttributeParsingException("Missing attribute specifier.");
}
}
TrimComments();
// create the attribute object
IdlAttribute *attrObj = new IdlAttribute();
attrObj->SetReadOnly(isReadOnly);
// this must be the attribute type
token = mScanner->NextToken();
switch(token->id) {
// base type
case BOOLEAN_TOKEN:
attrObj->SetType(TYPE_BOOLEAN);
break;
case FLOAT_TOKEN:
attrObj->SetType(TYPE_FLOAT);
break;
case DOUBLE_TOKEN:
attrObj->SetType(TYPE_DOUBLE);
break;
case LONG_TOKEN:
attrObj->SetType(TYPE_LONG);
break;
case SHORT_TOKEN:
attrObj->SetType(TYPE_SHORT);
break;
case ULONG_TOKEN:
attrObj->SetType(TYPE_ULONG);
break;
case USHORT_TOKEN:
attrObj->SetType(TYPE_USHORT);
break;
case CHAR_TOKEN:
attrObj->SetType(TYPE_CHAR);
break;
case INT_TOKEN:
attrObj->SetType(TYPE_INT);
break;
case UINT_TOKEN:
attrObj->SetType(TYPE_UINT);
break;
// string type
case STRING_TOKEN:
attrObj->SetType(TYPE_STRING);
break;
// scoped name
case IDENTIFIER_TOKEN:
//if (aSpecification.ContainInterface(token->stringID)) {
attrObj->SetType(TYPE_OBJECT);
attrObj->SetTypeName(token->stringID);
break;
//}
default:
delete attrObj;
throw AttributeParsingException("Unknow attribute type.");
}
TrimComments();
// an identifier must follow
token = mScanner->NextToken();
if (IDENTIFIER_TOKEN == token->id) {
attrObj->SetName(token->stringID);
}
else {
delete attrObj;
throw AttributeParsingException("Missing identifire. Attribute name undefined.");
}
return attrObj;
}
IdlFunction* IdlParser::ParseFunction(IdlSpecification &aSpecification, Token &aToken)
{
// NOTE: we don't process the function specifier "oneway"
IdlFunction *funcObj = new IdlFunction();
// a function name starts with the return value
switch(aToken.id) {
// base type
case BOOLEAN_TOKEN:
funcObj->SetReturnValue(TYPE_BOOLEAN);
break;
case FLOAT_TOKEN:
funcObj->SetReturnValue(TYPE_FLOAT);
break;
case DOUBLE_TOKEN:
funcObj->SetReturnValue(TYPE_DOUBLE);
break;
case LONG_TOKEN:
funcObj->SetReturnValue(TYPE_LONG);
break;
case SHORT_TOKEN:
funcObj->SetReturnValue(TYPE_SHORT);
break;
case ULONG_TOKEN:
funcObj->SetReturnValue(TYPE_ULONG);
break;
case USHORT_TOKEN:
funcObj->SetReturnValue(TYPE_USHORT);
break;
case CHAR_TOKEN:
funcObj->SetReturnValue(TYPE_CHAR);
break;
case INT_TOKEN:
funcObj->SetReturnValue(TYPE_INT);
break;
case UINT_TOKEN:
funcObj->SetReturnValue(TYPE_UINT);
break;
// string type
case STRING_TOKEN:
funcObj->SetReturnValue(TYPE_STRING);
break;
// scoped name
case IDENTIFIER_TOKEN:
//if (aSpecification.ContainInterface(aToken.stringID)) {
funcObj->SetReturnValue(TYPE_OBJECT, aToken.stringID);
break;
//}
default:
delete funcObj;
throw AttributeParsingException("Unknown type.");
}
Token *token;
TrimComments();
// must be the function name
token = mScanner->NextToken();
if (IDENTIFIER_TOKEN == token->id) {
funcObj->SetName(token->stringID);
TrimComments();
// must be "("
token = mScanner->PeekToken();
if (FUNC_PARAMS_SPEC_BEGIN_TOKEN == token->id) {
try {
while (FUNC_PARAMS_SPEC_END_TOKEN != token->id &&
(FUNC_PARAMS_SPEC_BEGIN_TOKEN == token->id ||
SEPARATOR_TOKEN == token->id)
) {
mScanner->NextToken(); // eat the last peeked symbol
TrimComments();
if (FUNC_PARAMS_SPEC_END_TOKEN == mScanner->PeekToken()->id) {
break;
}
// parse all arguments
funcObj->AddParameter(ParseFunctionParameter(aSpecification));
TrimComments();
token = mScanner->PeekToken();
}
mScanner->NextToken(); // eat ')'
}
catch (ParameterParsingException &) {
delete funcObj;
throw;
}
// is it throwing an exception?
TrimComments();
token = mScanner->PeekToken();
while (INTERFACE_TOKEN == token->id) {
mScanner->NextToken(); // eat "interface"
TrimComments();
token = mScanner->NextToken(); // must be the exception name
if (IDENTIFIER_TOKEN == token->id) {
funcObj->AddException(token->stringID);
TrimComments();
mScanner->NextToken(); // eat '{'
TrimComments();
mScanner->NextToken(); // eat '}'
TrimComments();
token = mScanner->PeekToken();
if (SEPARATOR_TOKEN == token->id) {
mScanner->NextToken(); // eat ','
TrimComments();
token = mScanner->PeekToken(); // should be next exception
}
}
else {
delete funcObj;
throw FunctionParsingException("Undeclared exception name.");
}
}
}
else {
delete funcObj;
throw FunctionParsingException("Missing '('. Parameters list undefined.");
}
}
else {
delete funcObj;
throw FunctionParsingException("Missing identifier. Function name undefined.");
}
return funcObj;
}
/**
* Parse a function argument
*
*/
IdlParameter* IdlParser::ParseFunctionParameter(IdlSpecification &aSpecification)
{
IdlParameter *argObj = new IdlParameter();
Token *token = mScanner->NextToken();
// the paramenter attribute (in, out, inout)
switch(token->id) {
// base type
case INPUT_PARAM_TOKEN:
argObj->SetAttribute(IdlParameter.INPUT);
break;
case OUTPUT_PARAM_TOKEN:
argObj->SetAttribute(IdlParameter.OUTPUT);
break;
case INOUT_PARAM_TOKEN:
argObj->SetAttribute(IdlParameter.INOUT);
break;
default:
delete argObj;
throw ParameterParsingException("Parameter attribute (in, out or inout) undefined.");
}
TrimComments();
token = mScanner->NextToken();
// must be a known type
switch(token->id) {
// base type
case BOOLEAN_TOKEN:
argObj->SetType(TYPE_BOOLEAN);
break;
case FLOAT_TOKEN:
argObj->SetType(TYPE_FLOAT);
break;
case DOUBLE_TOKEN:
argObj->SetType(TYPE_DOUBLE);
break;
case LONG_TOKEN:
argObj->SetType(TYPE_LONG);
break;
case SHORT_TOKEN:
argObj->SetType(TYPE_SHORT);
break;
case ULONG_TOKEN:
argObj->SetType(TYPE_ULONG);
break;
case USHORT_TOKEN:
argObj->SetType(TYPE_USHORT);
break;
case CHAR_TOKEN:
argObj->SetType(TYPE_CHAR);
break;
case INT_TOKEN:
argObj->SetType(TYPE_INT);
break;
case UINT_TOKEN:
argObj->SetType(TYPE_UINT);
break;
// string type
case STRING_TOKEN:
argObj->SetType(TYPE_STRING);
break;
// scoped name
case IDENTIFIER_TOKEN:
//if (aSpecification.ContainInterface(token->stringID)) {
argObj->SetType(TYPE_OBJECT);
argObj->SetTypeName(token->stringID);
break;
//}
default:
delete argObj;
throw ParameterParsingException("Unknow type in parameters list.");
}
TrimComments();
// must be the argument name
token = mScanner->NextToken();
if (IDENTIFIER_TOKEN == token->id) {
argObj->SetName(token->stringID);
}
else {
delete argObj;
throw ParameterParsingException("Missing identifier. Parameter name undefined.");
}
return argObj;
}
/**
* Skip all following comments
*
*/
void IdlParser::TrimComments()
{
while (COMMENT_TOKEN == mScanner->PeekToken()->id) {
mScanner->NextToken();
}
}

68
dom/tools/IdlParser.h Normal file
Просмотреть файл

@ -0,0 +1,68 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlParser_h__
#define _IdlParser_h__
#include "IdlObject.h"
#include "IdlScanner.h"
class IdlSpecification;
class IdlInterface;
class IdlTypedef;
class IdlStruct;
class IdlEnum;
class IdlUnion;
class IdlConst;
class IdlException;
class IdlAttribute;
class IdlFunction;
class IdlParameter;
class IdlParser {
private:
IdlScanner *mScanner;
public:
IdlParser();
~IdlParser();
void Parse(char *aFileName, IdlSpecification &aSpecification);
protected:
IdlInterface* ParseInterface(IdlSpecification &aSpecification);
void ParseInterfaceBody(IdlSpecification &aSpecification, IdlInterface &aInterface);
IdlTypedef* ParseTypedef(IdlSpecification &aSpecification);
IdlStruct* ParseStruct(IdlSpecification &aSpecification);
IdlEnum* ParseEnum(IdlSpecification &aSpecification);
IdlUnion* ParseUnion(IdlSpecification &aSpecification);
IdlConst* ParseConst(IdlSpecification &aSpecification);
IdlException* ParseException(IdlSpecification &aSpecification);
IdlAttribute* ParseAttribute(IdlSpecification &aSpecification, int aTokenID);
IdlFunction* ParseFunction(IdlSpecification &aSpecification, Token &aToken);
IdlParameter* ParseFunctionParameter(IdlSpecification &aSpecification);
void TrimComments();
};
#endif // _IdlParser_h__

1163
dom/tools/IdlScanner.cpp Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

201
dom/tools/IdlScanner.h Normal file
Просмотреть файл

@ -0,0 +1,201 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlScanner_h__
#define _IdlScanner_h__
#include <string.h>
class ifstream;
#define MAX_ID_LENGHT 256
enum TokenType {
EOF_TOKEN = -1,
ERROR_TOKEN = 0,
COMMENT_TOKEN = 1,
INTERFACE_TOKEN,
TYPEDEF_TOKEN,
STRUCT_TOKEN,
ENUM_TOKEN,
UNION_TOKEN,
CONST_TOKEN,
EXCEPTION_TOKEN,
READONLY_TOKEN,
ATTRIBUTE_TOKEN,
IDENTIFIER_TOKEN,
BOOLEAN_TOKEN,
FLOAT_TOKEN,
DOUBLE_TOKEN,
LONG_TOKEN,
SHORT_TOKEN,
ULONG_TOKEN,
USHORT_TOKEN,
CHAR_TOKEN,
INT_TOKEN,
UINT_TOKEN,
STRING_TOKEN,
INPUT_PARAM_TOKEN,
OUTPUT_PARAM_TOKEN,
INOUT_PARAM_TOKEN,
INHERITANCE_SPEC_TOKEN, // ':'
SEPARATOR_TOKEN, // ','
BEGIN_BLOCK_TOKEN, // '{'
END_BLOCK_TOKEN, // '}'
TERMINATOR_TOKEN, // ';'
ASSIGNEMENT_TOKEN, // '='
FUNC_PARAMS_SPEC_BEGIN_TOKEN, // '('
FUNC_PARAMS_SPEC_END_TOKEN, // ')'
// temp, it changes to ushort or uint or ulong
UNSIGNED_TOKEN,
// constant values
INTEGER_CONSTANT = 1000,
STRING_CONSTANT
};
struct Token {
int id;
char *stringID;
union {
// long is the only one used so far
unsigned long vLong;
// still unused...
char vChar;
char *vString;
double vDouble;
} value;
Token()
{
id = 0;
stringID = (char*)0;
memset(&value, 0, sizeof(value));
}
~Token()
{
if (STRING_CONSTANT == id) {
delete[] value.vString;
}
delete[] stringID;
}
void SetToken(int aID, char *aString = 0)
{
if (STRING_CONSTANT == id) {
delete[] value.vString;
}
id = aID;
if (stringID) {
delete[] stringID;
}
if (aString) {
stringID = new char[strlen(aString) + 1];
memcpy(stringID, aString, strlen(aString) + 1);
}
else {
stringID = (char*)0;
}
memset(&value, 0, sizeof(value));
}
void SetTokenValue(int aID, long aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vLong = (unsigned long)aValue;
}
void SetTokenValue(int aID, char aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vChar = aValue;
}
void SetTokenValue(int aID, char *aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vString = aValue;
}
void SetTokenValue(int aID, double aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vDouble = aValue;
}
};
class IdlScanner {
private:
ifstream *mInputFile;
char *mFileName;
Token *mToken1;
Token *mToken2;
Token *mCurrentToken;
long mLineNumber;
int mTokenPeeked;
char mTokenName[MAX_ID_LENGHT];
public:
IdlScanner();
~IdlScanner();
char* GetFileName();
void SetFileName(char *aFileName);
long GetLineNumber();
int Open(char *aFileName);
int CanReadMoreData();
Token* PeekToken();
Token* NextToken();
protected:
void SetCurrentToken();
int EatWhiteSpace();
void AKeywords(char *aCurrentPos, Token *aToken);
void BKeywords(char *aCurrentPos, Token *aToken);
void CKeywords(char *aCurrentPos, Token *aToken);
void DKeywords(char *aCurrentPos, Token *aToken);
void EKeywords(char *aCurrentPos, Token *aToken);
void FKeywords(char *aCurrentPos, Token *aToken);
void IKeywords(char *aCurrentPos, Token *aToken);
void LKeywords(char *aCurrentPos, Token *aToken);
void OKeywords(char *aCurrentPos, Token *aToken);
void RKeywords(char *aCurrentPos, Token *aToken);
void SKeywords(char *aCurrentPos, Token *aToken);
void TKeywords(char *aCurrentPos, Token *aToken);
void UKeywords(char *aCurrentPos, Token *aToken);
void WKeywords(char *aCurrentPos, Token *aToken);
void Identifier(char *aCurrentPos, Token *aToken);
void Number(int aStartChar, Token *aToken);
void String(int aStartChar, Token *aToken);
void Char(int aStartChar, Token *aToken);
void Comment(char *aCurrentPos, Token *aToken);
void KeywordMismatch(int aChar, char *aCurrentPos, Token *aToken);
};
#endif // _IdlScanner_h__

Просмотреть файл

@ -0,0 +1,84 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "IdlSpecification.h"
#include "IdlInterface.h"
#include "nsVoidArray.h"
#include <string.h>
IdlSpecification::IdlSpecification()
{
mInterfaces = (nsVoidArray*)0;
}
IdlSpecification::~IdlSpecification()
{
if (mInterfaces) {
for (int i = 0; i < mInterfaces->Count(); i++) {
IdlInterface *interfaceObj = (IdlInterface*)mInterfaces->ElementAt(i);
delete interfaceObj;
}
}
}
void IdlSpecification::AddInterface(IdlInterface *aInterface)
{
if (aInterface) {
if (mInterfaces == 0) {
mInterfaces = new nsVoidArray();
}
mInterfaces->AppendElement((void*)aInterface);
}
}
int IdlSpecification::ContainInterface(char *aInterfaceName)
{
if (mInterfaces) {
for (int i = 0; i < mInterfaces->Count(); i++) {
IdlInterface *interfaceObj = (IdlInterface*)mInterfaces->ElementAt(i);
if (0 == strcmp(interfaceObj->GetName(), aInterfaceName)) {
return 1;
}
}
}
return 0;
}
IdlInterface* IdlSpecification::GetInterfaceAt(long aIndex)
{
IdlInterface *interfaceObj = (IdlInterface*)0;
if (mInterfaces) {
interfaceObj = (IdlInterface*)mInterfaces->ElementAt(aIndex);
}
return interfaceObj;
}
long IdlSpecification::InterfaceCount()
{
if (mInterfaces) {
return mInterfaces->Count();
}
return 0;
}

Просмотреть файл

@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlSpecification_h__
#define _IdlSpecification_h__
#include "IdlObject.h"
class IdlInterface;
class nsVoidArray;
class IdlSpecification : public IdlObject {
private:
nsVoidArray *mInterfaces;
public:
IdlSpecification();
~IdlSpecification();
void AddInterface(IdlInterface *aInterface);
int ContainInterface(char *aInterfaceName);
IdlInterface* GetInterfaceAt(long aIndex);
long InterfaceCount();
};
#endif

141
dom/tools/IdlVariable.cpp Normal file
Просмотреть файл

@ -0,0 +1,141 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "IdlVariable.h"
#include <string.h>
IdlVariable::IdlVariable()
{
mType = (Type)0;
mTypeName = 0;
memset(&mValue, 0, sizeof(mValue));
}
IdlVariable::~IdlVariable()
{
if (mTypeName) {
delete[] mTypeName;
}
if (TYPE_STRING == mType) {
delete[] mValue.vString;
}
}
void IdlVariable::SetType(Type aType)
{
mType = aType;
}
Type IdlVariable::GeType()
{
return mType;
}
void IdlVariable::SetTypeName(char *aTypeName)
{
if (mTypeName) {
delete[] mTypeName;
mTypeName = 0;
}
if (aTypeName) {
size_t length = strlen(aTypeName) + 1;
mTypeName = new char[length];
strcpy(mTypeName, aTypeName);
}
}
char* IdlVariable::GetTypeName()
{
return mTypeName;
}
void IdlVariable::SetValue(unsigned long aValue)
{
DeleteStringType();
mType = TYPE_ULONG;
mValue.vLong = aValue;
}
void IdlVariable::SetValue(char aValue)
{
DeleteStringType();
mType = TYPE_CHAR;
mValue.vChar = aValue;
}
void IdlVariable::SetValue(char *aValue)
{
DeleteStringType();
mType = TYPE_STRING;
size_t length = strlen(aValue) + 1;
mValue.vString = new char[length];
strcpy(mValue.vString, aValue);
}
void IdlVariable::SetValue(double aValue)
{
DeleteStringType();
mType = TYPE_DOUBLE;
mValue.vDouble = aValue;
}
void IdlVariable::SetValue(void *aValue)
{
DeleteStringType();
mType = TYPE_OBJECT;
mValue.vObject = aValue;
}
unsigned long IdlVariable::GetLongValue()
{
return mValue.vLong;
}
char IdlVariable::GetCharValue()
{
return mValue.vChar;
}
char* IdlVariable::GetStringValue()
{
return mValue.vString;
}
double IdlVariable::GetDoubleValue()
{
return mValue.vDouble;
}
void* IdlVariable::GetObjectValue()
{
return mValue.vObject;
}
void IdlVariable::DeleteStringType()
{
if (TYPE_STRING == mType) {
if (mValue.vString) {
delete[] mValue.vString;
}
}
}

77
dom/tools/IdlVariable.h Normal file
Просмотреть файл

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _IdlVariable_h__
#define _IdlVariable_h__
#include "IdlObject.h"
enum Type {
TYPE_BOOLEAN = 1,
TYPE_FLOAT,
TYPE_DOUBLE,
TYPE_LONG,
TYPE_SHORT,
TYPE_ULONG,
TYPE_USHORT,
TYPE_CHAR,
TYPE_INT,
TYPE_UINT,
TYPE_STRING,
TYPE_OBJECT
};
class IdlVariable : public IdlObject {
private:
Type mType;
char *mTypeName;
union {
unsigned long vLong;
char vChar;
char *vString;
double vDouble;
void *vObject;
} mValue;
public:
IdlVariable();
~IdlVariable();
void SetType(Type aType);
Type GeType();
void SetTypeName(char *aTypeName);
char* GetTypeName();
void SetValue(unsigned long aValue);
void SetValue(char aValue);
void SetValue(char *aValue);
void SetValue(double aValue);
void SetValue(void *aValue);
unsigned long GetLongValue();
char GetCharValue();
char* GetStringValue();
double GetDoubleValue();
void* GetObjectValue();
private:
void DeleteStringType();
};
#endif

61
dom/tools/Makefile Normal file
Просмотреть файл

@ -0,0 +1,61 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=../..
include $(DEPTH)/config/config.mk
CPPSRCS = \
.\$(OBJDIR)\main.obj \
.\$(OBJDIR)\IdlParser.obj \
.\$(OBJDIR)\IdlScanner.obj \
.\$(OBJDIR)\Exceptions.obj \
.\$(OBJDIR)\IdlObject.obj \
.\$(OBJDIR)\IdlVariable.obj \
.\$(OBJDIR)\IdlAttribute.obj \
.\$(OBJDIR)\IdlEnum.obj \
.\$(OBJDIR)\IdlFunction.obj \
.\$(OBJDIR)\IdlInterface.obj \
.\$(OBJDIR)\IdlParameter.obj \
.\$(OBJDIR)\IdlSpecification.obj\
$(NULL)
OBJS = $(CPPSRCS:.cpp=.o)
EX_LIBS = \
$(NULL)
PROGS = $(addprefix $(OBJDIR)/, $(CPPSRCS:.cpp=))
NON_DIRS = $(PROGS)
TARGETS = $(NON_DIRS)
include $(DEPTH)/config/rules.mk
$(OBJDIR)/%.o: %.cpp
@$(MAKE_OBJDIR)
$(CCC) -o $@ $(CFLAGS) -DUSE_NSREG -c $*.cpp
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(EX_LIBS)
@$(MAKE_OBJDIR)
$(CCC) -o $@ $@.o $(LDFLAGS) $(EX_LIBS) $(OS_LIBS)
export::
install:: $(PROGS)
$(INSTALL) $(PROGS) $(DIST)/bin

58
dom/tools/Makefile.win Normal file
Просмотреть файл

@ -0,0 +1,58 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = EXE
PROGRAM = .\$(OBJDIR)\idlc.exe
OBJS = \
.\$(OBJDIR)\main.obj \
.\$(OBJDIR)\IdlParser.obj \
.\$(OBJDIR)\IdlScanner.obj \
.\$(OBJDIR)\Exceptions.obj \
.\$(OBJDIR)\IdlObject.obj \
.\$(OBJDIR)\IdlVariable.obj \
.\$(OBJDIR)\IdlAttribute.obj \
.\$(OBJDIR)\IdlEnum.obj \
.\$(OBJDIR)\IdlFunction.obj \
.\$(OBJDIR)\IdlInterface.obj \
.\$(OBJDIR)\IdlParameter.obj \
.\$(OBJDIR)\IdlSpecification.obj\
$(NULL)
LLIBS= \
$(DIST)\lib\raptorbase.lib \
-SUBSYSTEM:CONSOLE
LINCS= \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\xpcom \
$(NULL)
LCFLAGS = $(LCFLAGS) -GX
include <$(DEPTH)\config\rules.mak>
install:: $(PROGRAM)
echo $(OS_CFLAGS)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
clobber::
rm -f $(DIST)\bin\idlc.exe

87
dom/tools/main.cpp Normal file
Просмотреть файл

@ -0,0 +1,87 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
// initialize cout
#include "ostream.h"
#include "string.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <direct.h>
#include "IdlParser.h"
#include "Exceptions.h"
#include "IdlSpecification.h"
int main(int argc, char *argv[])
{
// extract filenames from argv
if (argc >= 2) {
int args = argc - 1;
// test if an output directory is provided
if (args > 1) {
int createDir = 1;
size_t length = strlen(argv[args]);
if (length > 4) {
if (0 == strcmp(argv[args] + length - 4, ".idl")) {
createDir = 0;
}
}
if (createDir) {
struct stat sb;
if (stat(argv[args], &sb) == 0) {
if (!(sb.st_mode & _S_IFDIR)) {
cout << "Creating directory " << argv[args] << " ...\n";
if (mkdir(argv[args]) < 0) {
cout << "WARNING: cannot create output directory [" << argv[args] << "]\n";
cout << "++++++++ using current directory\n";
}
}
}
args--;
}
}
for (int i = 1; i <= args; i++) {
// create a specification object. On parser termination it will
// contain all parsed interfaces
IdlSpecification *specification = new IdlSpecification();
// initialize and run the parser
IdlParser *parser = new IdlParser();
try {
parser->Parse(argv[i], *specification);
} catch(AbortParser &exc) {
cout << exc;
delete parser;
return -1;
} catch(...) {
cout << "Unknown Exception. Parser Aborted.";
}
delete parser;
}
return 0;
}
cout << "ERROR: no file specified\n";
return -1;
}