pjs/dom/tools/IdlFunction.cpp

170 строки
3.7 KiB
C++
Исходник Обычный вид История

1998-05-13 00:30:45 +04:00
/* -*- 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"
1998-05-15 22:49:17 +04:00
#include <string.h>
#include <ostream.h>
1998-05-13 00:30:45 +04:00
1998-05-15 22:49:17 +04:00
ostream& operator<<(ostream &s, IdlFunction &aFunction)
{
char type[128];
aFunction.GetReturnValue()->GetTypeAsString(type, 128);
s << type << " " << aFunction.GetName() << "(";
long count = aFunction.ParameterCount();
if (count) {
for (int i = 0; i < count - 1; i++) {
s << *(aFunction.GetParameterAt(i)) << ", ";
}
s << *(aFunction.GetParameterAt(count - 1));
}
if (aFunction.GetHasEllipsis()) {
s << ",...";
}
1998-05-15 22:49:17 +04:00
s << ")";
count = aFunction.ExceptionCount();
if (count) {
s << " raises (";
for (int i = 0; i < count - 1; i++) {
s << aFunction.GetExceptionAt(i) << ", ";
}
s << aFunction.GetExceptionAt(count - 1) << ")";
}
return s << ";";
}
1998-05-13 00:30:45 +04:00
IdlFunction::IdlFunction()
{
mReturnValue = (IdlVariable*)0;
mParameters = (nsVoidArray*)0;
mExceptions = (nsVoidArray*)0;
mHasEllipsis = 0;
1998-05-13 00:30:45 +04:00
}
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++) {
1998-05-15 22:49:17 +04:00
char *exc = (char*)mExceptions->ElementAt(i);
delete[] exc;
1998-05-13 00:30:45 +04:00
}
}
}
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();
}
1998-05-15 22:49:17 +04:00
char *exc = new char[strlen(aException) + 1];
strcpy(exc, aException);
mExceptions->AppendElement((void*)exc);
1998-05-13 00:30:45 +04:00
}
}
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;
}
int
IdlFunction::GetHasEllipsis()
{
return mHasEllipsis;
}
void
IdlFunction::SetHasEllipsis(int aHasEllipsis)
{
mHasEllipsis = aHasEllipsis;
}
1998-05-13 00:30:45 +04:00