cdlcompilertoolkit/src/CdlTkInterface.cpp
changeset 0 f58d6ec98e88
equal deleted inserted replaced
-1:000000000000 0:f58d6ec98e88
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include "CdlCompilerToolkit/CdlTkInterface.h"
       
    18 #include "CdlTkPriv.h"
       
    19 #include "CdlTkStdTrans.h"
       
    20 #include <sstream>
       
    21 #include <CdlDef.h>
       
    22 using namespace std;
       
    23 
       
    24 namespace CdlCompilerToolkit {
       
    25 
       
    26 //
       
    27 // TCdlTkFlag
       
    28 //
       
    29 
       
    30 struct TCdlTkFlag
       
    31 	{
       
    32 	const char* iName;
       
    33 	int iValue;
       
    34 	};
       
    35 
       
    36 const TCdlTkFlag gCdlTkFlags[] =
       
    37 	{
       
    38 		{ "KCdlFlagRomOnly", KCdlFlagRomOnlyValue }
       
    39 	};
       
    40 
       
    41 
       
    42 //
       
    43 // CCdlTkInterfaceHeader::CFlags
       
    44 //
       
    45 
       
    46 CCdlTkInterfaceHeader::CFlags::CFlags()
       
    47 : iFlags(0)
       
    48 	{
       
    49 	}
       
    50 
       
    51 void CCdlTkInterfaceHeader::CFlags::SetFlag(const string& aFlagName)
       
    52 	{
       
    53 	iFlags |= FlagVal(aFlagName);
       
    54 	}
       
    55 
       
    56 void CCdlTkInterfaceHeader::CFlags::ClearFlag(const string& aFlagName)
       
    57 	{
       
    58 	iFlags &= ~FlagVal(aFlagName);
       
    59 	}
       
    60 
       
    61 int CCdlTkInterfaceHeader::CFlags::FlagsAsInt() const
       
    62 	{
       
    63 	return iFlags;
       
    64 	}
       
    65 
       
    66 string CCdlTkInterfaceHeader::CFlags::FlagsAsString() const
       
    67 	{
       
    68 	string flags;
       
    69 	for (int bit=0; bit<Count(); bit++)
       
    70 		{
       
    71 		if (IsSet(bit))
       
    72 			{
       
    73 			if (!flags.empty())
       
    74 				CdlTkUtil::AppendString(flags, " | ");
       
    75 			CdlTkUtil::AppendString(flags, FlagName(bit));
       
    76 			}
       
    77 		}
       
    78 	if (flags.empty())
       
    79 		flags = "0";
       
    80 	return flags;
       
    81 	}
       
    82 
       
    83 int CCdlTkInterfaceHeader::CFlags::FlagVal(const string& aFlagName) const
       
    84 	{
       
    85 	for (int ii=0; ii<Count(); ii++)
       
    86 		{
       
    87 		const TCdlTkFlag& flag = gCdlTkFlags[ii];
       
    88 		if (aFlagName == flag.iName)
       
    89 			return flag.iValue;
       
    90 		}
       
    91 	throw CdlTkAssert(aFlagName + " : unknown flag");
       
    92 	return 0;
       
    93 	}
       
    94 
       
    95 string CCdlTkInterfaceHeader::CFlags::FlagName(int aFlagIndex) const
       
    96 	{
       
    97 	int flagVal = IndexToFlagVal(aFlagIndex);
       
    98 	for (int ii=0; ii<Count(); ii++)
       
    99 		{
       
   100 		const TCdlTkFlag& flag = gCdlTkFlags[ii];
       
   101 		if (flagVal == flag.iValue)
       
   102 			return flag.iName;
       
   103 		}
       
   104 	throw CdlTkAssert(CdlTkUtil::IntToString(aFlagIndex) + " : unknown flag index");
       
   105 	return "";
       
   106 	}
       
   107 
       
   108 int CCdlTkInterfaceHeader::CFlags::Count() const
       
   109 	{
       
   110 	return sizeof(gCdlTkFlags)/sizeof(*gCdlTkFlags);
       
   111 	}
       
   112 
       
   113 int CCdlTkInterfaceHeader::CFlags::IndexToFlagVal(int aIndex) const
       
   114 	{
       
   115 	return 1<<aIndex;
       
   116 	}
       
   117 
       
   118 bool CCdlTkInterfaceHeader::CFlags::IsSet(int aFlagIndex) const
       
   119 	{
       
   120 	return !!(iFlags & IndexToFlagVal(aFlagIndex));
       
   121 	}
       
   122 
       
   123 bool CCdlTkInterfaceHeader::CFlags::IsSet(const string& aFlagName) const
       
   124 	{
       
   125 	return !!(iFlags & FlagVal(aFlagName));
       
   126 	}
       
   127 
       
   128 CCdlTkInterfaceHeader::CFlags& CCdlTkInterfaceHeader::CFlags::operator|=(const CFlags& aOther)
       
   129 	{
       
   130 	iFlags |= aOther.iFlags;
       
   131 	return *this;
       
   132 	}
       
   133 
       
   134 
       
   135 //
       
   136 // CCdlTkInterfaceHeader::CVersion
       
   137 //
       
   138 
       
   139 CCdlTkInterfaceHeader::CVersion::CVersion()
       
   140 : iMajor(0), iMinor(0)
       
   141 	{
       
   142 	}
       
   143 
       
   144 CCdlTkInterfaceHeader::CVersion::CVersion(int aMajor, int aMinor)
       
   145 : iMajor(aMajor), iMinor(aMinor)
       
   146 	{
       
   147 	}
       
   148 
       
   149 bool CCdlTkInterfaceHeader::CVersion::operator<(const CVersion aOther) const
       
   150 	{
       
   151 	return  (iMajor < aOther.iMajor) ||
       
   152 			(iMajor == aOther.iMajor && iMinor < aOther.iMinor);
       
   153 	}
       
   154 
       
   155 bool CCdlTkInterfaceHeader::CVersion::operator==(const CVersion aOther) const
       
   156 	{
       
   157 	return iMajor == aOther.iMajor && iMinor == aOther.iMinor;
       
   158 	}
       
   159 
       
   160 int CCdlTkInterfaceHeader::CVersion::Major() const
       
   161 	{
       
   162 	return iMajor;
       
   163 	}
       
   164 
       
   165 void CCdlTkInterfaceHeader::CVersion::SetMajor(int aMajor)
       
   166 	{
       
   167 	iMajor = aMajor;
       
   168 	}
       
   169 
       
   170 int CCdlTkInterfaceHeader::CVersion::Minor() const
       
   171 	{
       
   172 	return iMinor;
       
   173 	}
       
   174 
       
   175 void CCdlTkInterfaceHeader::CVersion::SetMinor(int aMinor)
       
   176 	{
       
   177 	iMinor = aMinor;
       
   178 	}
       
   179 
       
   180 
       
   181 //
       
   182 // CCdlTkInterfaceHeader
       
   183 //
       
   184 
       
   185 CCdlTkInterfaceHeader::CCdlTkInterfaceHeader()
       
   186 : iName(""), iUid(0), iVer(0, 0)
       
   187 	{
       
   188 	}
       
   189 
       
   190 void CCdlTkInterfaceHeader::MergeExtensionHeader(const CCdlTkInterfaceHeader& aOther)
       
   191 	{
       
   192 	if (!aOther.iName.empty() && iName != aOther.iName)
       
   193 		throw CdlTkAssert("Can't change interface name in extension");
       
   194 	if (aOther.iUid && iUid != aOther.iUid)
       
   195 		throw CdlTkAssert("Can't change interface UID in extension");
       
   196 	if (!(iVer < aOther.iVer))
       
   197 		throw CdlTkAssert("Interface version must increase in extension");
       
   198 	iVer = aOther.iVer;
       
   199 	iFlags |= aOther.iFlags;
       
   200 	}
       
   201 
       
   202 string CCdlTkInterfaceHeader::Name() const
       
   203 	{
       
   204 	return iName;
       
   205 	}
       
   206 
       
   207 void CCdlTkInterfaceHeader::SetName(const string& aName)
       
   208 	{
       
   209 	iName = aName;
       
   210 	}
       
   211 
       
   212 int CCdlTkInterfaceHeader::Uid() const
       
   213 	{
       
   214 	return iUid;
       
   215 	}
       
   216 
       
   217 void CCdlTkInterfaceHeader::SetUid(int aUid)
       
   218 	{
       
   219 	iUid = aUid;
       
   220 	}
       
   221 
       
   222 void CCdlTkInterfaceHeader::SetVersion(const CVersion& aVer)
       
   223 	{
       
   224 	iVer = aVer;
       
   225 	}
       
   226 
       
   227 const CCdlTkInterfaceHeader::CVersion& CCdlTkInterfaceHeader::Version() const
       
   228 	{
       
   229 	return iVer;
       
   230 	}
       
   231 
       
   232 const CCdlTkInterfaceHeader::CFlags& CCdlTkInterfaceHeader::Flags() const
       
   233 	{
       
   234 	return iFlags;
       
   235 	}
       
   236 
       
   237 CCdlTkInterfaceHeader::CFlags& CCdlTkInterfaceHeader::Flags()
       
   238 	{
       
   239 	return iFlags;
       
   240 	}
       
   241 
       
   242 bool CCdlTkInterfaceHeader::operator==(const CCdlTkInterfaceHeader& aOther) const
       
   243 	{
       
   244 	return 
       
   245 		iName == aOther.iName &&
       
   246 		iUid == aOther.iUid &&
       
   247 		iVer == aOther.iVer;
       
   248 	}
       
   249 
       
   250 
       
   251 //
       
   252 // CCdlTkApiParam
       
   253 //
       
   254 
       
   255 CCdlTkApiParam::CCdlTkApiParam()
       
   256 	{
       
   257 	}
       
   258 
       
   259 CCdlTkApiParam::CCdlTkApiParam(const string& aType, const string& aName)
       
   260 : iType(aType), iName(aName)
       
   261 	{
       
   262 	}
       
   263 
       
   264 CCdlTkApiParam::CCdlTkApiParam(const string& aType, const string& aName, const std::string& aDefaultValue)
       
   265 : iType(aType), iName(aName), iDefaultValue(aDefaultValue)
       
   266 	{
       
   267 	}
       
   268 
       
   269 const string& CCdlTkApiParam::Type() const
       
   270 	{
       
   271 	return iType;
       
   272 	}
       
   273 
       
   274 void CCdlTkApiParam::SetType(const string& aType)
       
   275 	{
       
   276 	iType = aType;
       
   277 	}
       
   278 
       
   279 const string& CCdlTkApiParam::Name() const
       
   280 	{
       
   281 	return iName;
       
   282 	}
       
   283 
       
   284 void CCdlTkApiParam::SetName(const string& aName)
       
   285 	{
       
   286 	iName = aName;
       
   287 	}
       
   288 
       
   289 const string& CCdlTkApiParam::DefaultValue() const
       
   290 	{
       
   291 	return iDefaultValue;
       
   292 	}
       
   293 
       
   294 void CCdlTkApiParam::SetDefaultValue(const std::string& aDefaultValue)
       
   295 	{
       
   296 	iDefaultValue = aDefaultValue;
       
   297 	}
       
   298 
       
   299 
       
   300 bool CCdlTkApiParam::operator==(const CCdlTkApiParam& aOther) const
       
   301 	{
       
   302 	return Type() == aOther.Type() && Name() == aOther.Name() && DefaultValue() == aOther.DefaultValue();
       
   303 	}
       
   304 
       
   305 
       
   306 CCdlTkApiParams::iterator CCdlTkApiParams::FindByName(string aParamName)
       
   307 	{
       
   308 	iterator it;
       
   309 	for (it = begin(); it != end(); ++it)
       
   310 		{
       
   311 		if (it->Name() == aParamName)
       
   312 			break;
       
   313 		}
       
   314 	return it;
       
   315 	}
       
   316 
       
   317 
       
   318 //
       
   319 // CCdlTkApi
       
   320 //
       
   321 
       
   322 CCdlTkApi::CCdlTkApi(CCdlTkInterface& aInterface)
       
   323 : iInterface(aInterface)
       
   324 	{
       
   325 	}
       
   326 
       
   327 CCdlTkApi::~CCdlTkApi()
       
   328 	{
       
   329 	}
       
   330 
       
   331 const string& CCdlTkApi::ReturnType() const
       
   332 	{
       
   333 	return iReturnType;
       
   334 	}
       
   335 
       
   336 void CCdlTkApi::SetReturnType(const string& aType)
       
   337 	{
       
   338 	iReturnType = aType;
       
   339 	}
       
   340 
       
   341 bool CCdlTkApi::IsVoidReturn() const
       
   342 	{
       
   343 	return iReturnType == "void";
       
   344 	}
       
   345 
       
   346 const string& CCdlTkApi::Name() const
       
   347 	{
       
   348 	return iName;
       
   349 	}
       
   350 
       
   351 void CCdlTkApi::SetName(const string& aName)
       
   352 	{
       
   353 	iName = aName;
       
   354 	}
       
   355 
       
   356 int CCdlTkApi::SourceFileLineNum() const
       
   357 	{
       
   358 	return iSourceFileLineNum;
       
   359 	}
       
   360 
       
   361 void CCdlTkApi::SetSourceFileLineNum(int aLineNum)
       
   362 	{
       
   363 	iSourceFileLineNum = aLineNum;
       
   364 	}
       
   365 
       
   366 const string& CCdlTkApi::Comment() const
       
   367 	{
       
   368 	return iComment;
       
   369 	}
       
   370 
       
   371 void CCdlTkApi::SetComment(const string& aComment)
       
   372 	{
       
   373 	iComment = aComment;
       
   374 	}
       
   375 
       
   376 const CCdlTkInterface& CCdlTkApi::Interface() const
       
   377 	{
       
   378 	return iInterface;
       
   379 	}
       
   380 
       
   381 CCdlTkInterface& CCdlTkApi::Interface()
       
   382 	{
       
   383 	return iInterface;
       
   384 	}
       
   385 
       
   386 const CCdlTkFunctionApi& CCdlTkApi::AsFunc() const
       
   387 	{
       
   388 	if (!IsFunc())
       
   389 		throw CdlTkAssert("API is not a function");
       
   390 	return static_cast<const CCdlTkFunctionApi&>(*this);
       
   391 	}
       
   392 
       
   393 const CCdlTkDataApi& CCdlTkApi::AsData() const
       
   394 	{
       
   395 	if (IsFunc())
       
   396 		throw CdlTkAssert("API is not data");
       
   397 	return static_cast<const CCdlTkDataApi&>(*this);
       
   398 	}
       
   399 
       
   400 bool CCdlTkApi::operator!=(const CCdlTkApi& aOther) const
       
   401 	{
       
   402 	return !(*this == aOther);
       
   403 	}
       
   404 
       
   405 bool CCdlTkApi::operator==(const CCdlTkApi& aOther) const
       
   406 	{
       
   407 	return 
       
   408 		ReturnType() == aOther.ReturnType() &&
       
   409 		Name() == aOther.Name() &&
       
   410 		IsFunc() == aOther.IsFunc();
       
   411 	}
       
   412 
       
   413 void CCdlTkApi::operator=(const CCdlTkApi& aOther)
       
   414 	{
       
   415 	iReturnType = aOther.iReturnType;
       
   416 	iName = aOther.iName;
       
   417 	iSourceFileLineNum = aOther.iSourceFileLineNum;
       
   418 	}
       
   419 
       
   420 
       
   421 //
       
   422 // CCdlTkDataApi
       
   423 //
       
   424 
       
   425 CCdlTkDataApi::CCdlTkDataApi(CCdlTkInterface& aInterface)
       
   426 : CCdlTkApi(aInterface)
       
   427 	{
       
   428 	}
       
   429 
       
   430 CCdlTkDataApi::CCdlTkDataApi(CCdlTkInterface& aInterface, const CCdlTkDataApi& aCopy)
       
   431 : CCdlTkApi(aInterface)
       
   432 	{
       
   433 	CCdlTkApi::operator=(aCopy);
       
   434 	}
       
   435 
       
   436 bool CCdlTkDataApi::IsFunc() const
       
   437 	{
       
   438 	return false;
       
   439 	}
       
   440 
       
   441 string CCdlTkDataApi::PointerType() const
       
   442 	{
       
   443 	return ReturnType() + " const*";
       
   444 	}
       
   445 
       
   446 string CCdlTkDataApi::ParamsTypeAndNameList() const
       
   447 	{
       
   448 	return "";
       
   449 	}
       
   450 
       
   451 CCdlTkApi* CCdlTkDataApi::Clone(CCdlTkInterface& aInterface) const
       
   452 	{
       
   453 	return new CCdlTkDataApi(aInterface, *this);
       
   454 	}
       
   455 
       
   456 
       
   457 //
       
   458 // CCdlTkFunctionApi
       
   459 //
       
   460 
       
   461 CCdlTkFunctionApi::CCdlTkFunctionApi(CCdlTkInterface& aInterface)
       
   462 : CCdlTkApi(aInterface)
       
   463 	{
       
   464 	}
       
   465 
       
   466 CCdlTkFunctionApi::CCdlTkFunctionApi(CCdlTkInterface& aInterface, const CCdlTkFunctionApi& aCopy)
       
   467 : CCdlTkApi(aInterface)
       
   468 	{
       
   469 	CCdlTkApi::operator=(aCopy);
       
   470 	iParams = aCopy.iParams;
       
   471 	}
       
   472 
       
   473 bool CCdlTkFunctionApi::IsFunc() const
       
   474 	{
       
   475 	return true;
       
   476 	}
       
   477 
       
   478 string CCdlTkFunctionApi::PointerType() const
       
   479 	{
       
   480 	return ApiNameAsTypeName() + "*";
       
   481 	}
       
   482 
       
   483 string CCdlTkFunctionApi::ParamsTypeAndNameList() const
       
   484 	{
       
   485 	string ret = "(";
       
   486 	for (CCdlTkApiParams::const_iterator pParam = iParams.begin(); pParam != iParams.end(); ++pParam)
       
   487 		{
       
   488 		if (pParam != iParams.begin())
       
   489 			CdlTkUtil::AppendString(ret, string(",") + KSpace);
       
   490 		CdlTkUtil::AppendString(ret, pParam->Type() + KSpace + pParam->Name());
       
   491 		if(!(pParam->DefaultValue().empty()))
       
   492 			CdlTkUtil::AppendString(ret, KSpace + KEqualsSign + KSpace + pParam->DefaultValue());
       
   493 		}
       
   494 	ret += ")";
       
   495 	return ret;
       
   496 	}
       
   497 
       
   498 CCdlTkApiParams& CCdlTkFunctionApi::Params()
       
   499 	{
       
   500 	return iParams;
       
   501 	}
       
   502 
       
   503 const CCdlTkApiParams& CCdlTkFunctionApi::Params() const
       
   504 	{
       
   505 	return iParams;
       
   506 	}
       
   507 
       
   508 string CCdlTkFunctionApi::ApiNameAsTypeName() const
       
   509 	{
       
   510 	string name = "T";
       
   511 	name += Name();
       
   512 	name += "_sig";
       
   513 	return name;
       
   514 	}
       
   515 
       
   516 string CCdlTkFunctionApi::ParamNameList() const
       
   517 	{
       
   518 	string ret = "";
       
   519 	for (CCdlTkApiParams::const_iterator pParam = iParams.begin(); pParam != iParams.end(); ++pParam)
       
   520 		{
       
   521 		if (pParam != iParams.begin())
       
   522 			CdlTkUtil::AppendString(ret, ", ");
       
   523 		CdlTkUtil::AppendString(ret, pParam->Name());
       
   524 		}
       
   525 	return ret;
       
   526 	}
       
   527 
       
   528 string CCdlTkFunctionApi::ParamTypeList() const
       
   529 	{
       
   530 	string ret = "";
       
   531 	for (CCdlTkApiParams::const_iterator pParam = iParams.begin(); pParam != iParams.end(); ++pParam)
       
   532 		{
       
   533 		if (pParam != iParams.begin())
       
   534 			CdlTkUtil::AppendString(ret, ", ");
       
   535 		CdlTkUtil::AppendString(ret, pParam->Type());
       
   536 		}
       
   537 	return ret;
       
   538 	}
       
   539 
       
   540 bool CCdlTkFunctionApi::operator==(const CCdlTkApi& aOther) const
       
   541 	{
       
   542 	return 
       
   543 		CCdlTkApi::operator==(aOther) && 
       
   544 		Params() == aOther.AsFunc().Params();	// calling AsFunc() is safe because base-class == will fail if this is not a function API
       
   545 	}
       
   546 
       
   547 CCdlTkApi* CCdlTkFunctionApi::Clone(CCdlTkInterface& aInterface) const
       
   548 	{
       
   549 	return new CCdlTkFunctionApi(aInterface, *this);
       
   550 	}
       
   551 
       
   552 
       
   553 //
       
   554 // CCdlTkApiList
       
   555 //
       
   556 
       
   557 CCdlTkApiList::CCdlTkApiList()
       
   558 	{
       
   559 	}
       
   560 
       
   561 void CCdlTkApiList::Copy(const CCdlTkApiList& aOther, CCdlTkInterface& aInterface)
       
   562 	{
       
   563 	if (this == &aOther)
       
   564 		return;
       
   565 	DeleteApis();
       
   566 	clear();
       
   567 	reserve(aOther.size());
       
   568 	for (const_iterator pApi = aOther.begin(); pApi != aOther.end(); ++pApi)
       
   569 		push_back((*pApi)->Clone(aInterface));
       
   570 	}
       
   571 
       
   572 CCdlTkApiList::~CCdlTkApiList()
       
   573 	{
       
   574 	DeleteApis();
       
   575 	}
       
   576 
       
   577 void CCdlTkApiList::DeleteApis()
       
   578 	{
       
   579 	for (iterator it = begin(); it != end(); ++it)
       
   580 		delete *it;
       
   581 	}
       
   582 
       
   583 void CCdlTkApiList::MergeExtendedApi(CCdlTkInterface& aInterface, const CCdlTkApiList& aOther)
       
   584 	{
       
   585 	for (const_iterator it = aOther.begin(); it != aOther.end(); ++it)
       
   586 		push_back((*it)->Clone(aInterface));
       
   587 	}
       
   588 
       
   589 CCdlTkApi* CCdlTkApiList::Find(const string& aName) const
       
   590 	{
       
   591 	for (const_iterator pApi = begin(); pApi != end(); ++pApi)
       
   592 		{
       
   593 		if ((*pApi)->Name() == aName)
       
   594 			return *pApi;
       
   595 		}
       
   596 	return 0;
       
   597 	}
       
   598 
       
   599 bool CCdlTkApiList::operator==(const CCdlTkApiList& aOther) const
       
   600 	{
       
   601 	if (size() != aOther.size())
       
   602 		return false;
       
   603 	const_iterator pOther = aOther.begin();
       
   604 	for (const_iterator pApi = begin(); pApi != end(); ++pApi)
       
   605 		{
       
   606 		if (**pApi != **pOther)
       
   607 			return false;
       
   608 		++pOther;
       
   609 		}
       
   610 	return true;
       
   611 	}
       
   612 
       
   613 bool CCdlTkApiList::IsSubsetOf(const CCdlTkApiList& aOther) const
       
   614 	{
       
   615 	for (const_iterator pApi = begin(); pApi != end(); ++pApi)
       
   616 		{
       
   617 		CCdlTkApi* api = aOther.Find((*pApi)->Name());
       
   618 		if (!api || **pApi != *api)
       
   619 			return false;
       
   620 		}
       
   621 	return true;
       
   622 	}
       
   623 
       
   624 
       
   625 //
       
   626 // CCdlTkCpp
       
   627 //
       
   628 
       
   629 CCdlTkCpp::CCdlTkCpp() 
       
   630 	{
       
   631 	}
       
   632 
       
   633 void CCdlTkCpp::MergeExtensionCpp(const CCdlTkCpp& aOther)
       
   634 	{
       
   635 	insert(end(), aOther.begin(), aOther.end());
       
   636 	}
       
   637 
       
   638 
       
   639 //
       
   640 // CCdlTkDataTypeTranslation
       
   641 //
       
   642 
       
   643 CCdlTkDataTypeTranslation::CCdlTkDataTypeTranslation()
       
   644 : iDefn(""), iPtrRef(""), iSource(EFromCdl)
       
   645 	{
       
   646 	SetType("");
       
   647 	}
       
   648 
       
   649 CCdlTkDataTypeTranslation::CCdlTkDataTypeTranslation(const string& aType)
       
   650 : iDefn(""), iPtrRef(""), iSource(EFromCdl)
       
   651 	{
       
   652 	SetType(aType);
       
   653 	}
       
   654 
       
   655 CCdlTkDataTypeTranslation::CCdlTkDataTypeTranslation(const string& aType, const string& aDefn, const string& aPtrRef, TTranslationSource aSource)
       
   656 : iDefn(aDefn), iPtrRef(aPtrRef), iSource(aSource)
       
   657 	{
       
   658 	SetType(aType);
       
   659 	}
       
   660 
       
   661 string CCdlTkDataTypeTranslation::Type() const
       
   662 	{
       
   663 	return iType;
       
   664 	}
       
   665 
       
   666 void CCdlTkDataTypeTranslation::SetType(const string& aType)
       
   667 	{
       
   668 	iType = aType;
       
   669 	iTypeSize = iType.size();
       
   670 	iTypeVarPos = iType.find(KType);
       
   671 	if (iTypeVarPos != string::npos)
       
   672 		{
       
   673 		iTypeSizeWithoutTypeVar = iTypeSize - KTypeSize;
       
   674 		iTextBeforeTypeVar = iType.substr(0, iTypeVarPos);
       
   675 		iTextAfterTypeVar = iType.substr(iTypeVarPos + KTypeSize);
       
   676 		iSizeAfterTypeVar = iTextAfterTypeVar.size();
       
   677 		}
       
   678 	}
       
   679 
       
   680 string CCdlTkDataTypeTranslation::Definition() const
       
   681 	{
       
   682 	return iDefn;
       
   683 	}
       
   684 
       
   685 void CCdlTkDataTypeTranslation::SetDefinition(const string& aDefn)
       
   686 	{
       
   687 	iDefn = aDefn;
       
   688 	}
       
   689 
       
   690 string CCdlTkDataTypeTranslation::PointerReference() const
       
   691 	{
       
   692 	return iPtrRef;
       
   693 	}
       
   694 
       
   695 void CCdlTkDataTypeTranslation::SetPointerReference(const string& aPtrRef)
       
   696 	{
       
   697 	iPtrRef = aPtrRef;
       
   698 	}
       
   699 
       
   700 CCdlTkDataTypeTranslation::TTranslationSource CCdlTkDataTypeTranslation::Source() const
       
   701 	{
       
   702 	return iSource;
       
   703 	}
       
   704 
       
   705 bool CCdlTkDataTypeTranslation::Match(const string& aType, string& aTypeVar) const
       
   706 	{
       
   707 	// KType is the string "aType". If this appears in iType, it matches
       
   708 	// any text in aType, and the matching text is placed in aTypeVar, otherwise
       
   709 	// aType must equal iType for a match to be found.
       
   710 	if (iTypeVarPos == string::npos)
       
   711 		{
       
   712 		// iType does not contain "aType". Give aTypeVar a dummy result
       
   713 		// and compare the two types.
       
   714 		aTypeVar = KType;
       
   715 		return iType == aType;
       
   716 		}
       
   717 	else
       
   718 		{
       
   719 		// iType contains the string "aType", so check if aType is big enough
       
   720 		// and that the start matches and the end matches.
       
   721 		int aTypeSize = aType.size();
       
   722 		if (iTypeSizeWithoutTypeVar >= aTypeSize ||
       
   723 			iTextBeforeTypeVar != aType.substr(0, iTypeVarPos) ||
       
   724 			iTextAfterTypeVar != aType.substr(aTypeSize - iSizeAfterTypeVar))
       
   725 			return false;
       
   726 		// Set aTypeVar to be the part of aType that corresponds to the string
       
   727 		// "aType".
       
   728 		aTypeVar = aType.substr(iTypeVarPos, aTypeSize - iTypeSizeWithoutTypeVar);
       
   729 		return true;
       
   730 		}
       
   731 	}
       
   732 
       
   733 bool CCdlTkDataTypeTranslation::operator==(const CCdlTkDataTypeTranslation& aOther) const
       
   734 	{
       
   735 	return
       
   736 		iType == aOther.iType &&
       
   737 		iDefn == aOther.iDefn &&
       
   738 		iPtrRef == aOther.iPtrRef &&
       
   739 		iSource == aOther.iSource;
       
   740 	}
       
   741 
       
   742 
       
   743 //
       
   744 // CCdlTkDataTypeTranslations
       
   745 //
       
   746 
       
   747 CCdlTkDataTypeTranslations::CCdlTkDataTypeTranslations()
       
   748 	{
       
   749 	// gStdTranslations is defined in CdlTkStdTrans.h
       
   750 	int count = sizeof(gStdTranslations)/sizeof(*gStdTranslations);
       
   751 	for (int ii=0; ii<count; ii++)
       
   752 		{
       
   753 		const SStdTranslation& trans = gStdTranslations[ii];
       
   754 		push_back(CCdlTkDataTypeTranslation(trans.iType, trans.iInit, trans.iRef, CCdlTkDataTypeTranslation::EInbuilt));
       
   755 		}
       
   756 	}
       
   757 
       
   758 void CCdlTkDataTypeTranslations::MergeExtensionTranslations(const CCdlTkDataTypeTranslations& aOther)
       
   759 	{
       
   760 	for (const_iterator pOther = aOther.begin(); pOther != aOther.end(); ++pOther)
       
   761 		{
       
   762 		if (pOther->Source() != CCdlTkDataTypeTranslation::EInbuilt)
       
   763 			push_back(*pOther);
       
   764 		}
       
   765 	}
       
   766 
       
   767 const CCdlTkDataTypeTranslation* CCdlTkDataTypeTranslations::Find(const string& aType, string& aTypeVar) const
       
   768 	{
       
   769 	for (const_reverse_iterator it = rbegin(); it != rend(); ++it)
       
   770 		{
       
   771 		if (it->Match(aType, aTypeVar))
       
   772 			return &*it;
       
   773 		}
       
   774 	return NULL;
       
   775 	}
       
   776 
       
   777 
       
   778 //
       
   779 // CCdlTkInterface
       
   780 //
       
   781 
       
   782 CCdlTkInterface::CCdlTkInterface()
       
   783 : iBase(0), iExtension(0)
       
   784 	{
       
   785 	}
       
   786 
       
   787 CCdlTkInterface::~CCdlTkInterface()
       
   788 	{
       
   789 	delete iExtension;
       
   790 	}
       
   791 
       
   792 CCdlTkInterface::CCdlTkInterface(const CCdlTkInterface& aCopy)
       
   793 : iBase(0), iExtension(0)
       
   794 	{
       
   795 	*this = aCopy;
       
   796 	}
       
   797 
       
   798 void CCdlTkInterface::operator=(const CCdlTkInterface& aCopy)
       
   799 	{
       
   800 	if (&aCopy == this)
       
   801 		return;
       
   802 
       
   803 	iFileName = aCopy.iFileName;
       
   804 	iHeader = aCopy.iHeader;
       
   805 	iCpp = aCopy.iCpp;
       
   806 	iApiList.Copy(aCopy.iApiList, *this);
       
   807 	iDataTypeTranslations = aCopy.iDataTypeTranslations;
       
   808 	iBase = aCopy.iBase;
       
   809 	delete iExtension;
       
   810 	iExtension = 0;
       
   811 	if (aCopy.iExtension)
       
   812 		iExtension = new CCdlTkInterface(*aCopy.iExtension);
       
   813 	}
       
   814 
       
   815 CCdlTkInterface* CCdlTkInterface::Base() const
       
   816 	{
       
   817 	return iBase;
       
   818 	}
       
   819 
       
   820 void CCdlTkInterface::SetBase(CCdlTkInterface* aBase)
       
   821 	{
       
   822 	iBase = aBase;
       
   823 	}
       
   824 
       
   825 CCdlTkInterface* CCdlTkInterface::Extension() const
       
   826 	{
       
   827 	return iExtension;
       
   828 	}
       
   829 
       
   830 void CCdlTkInterface::SetExtension(CCdlTkInterface* aExtension)
       
   831 	{
       
   832 	delete iExtension;
       
   833 	iExtension = aExtension;
       
   834 	}
       
   835 
       
   836 CCdlTkInterface* CCdlTkInterface::UltimateBase()
       
   837 	{
       
   838 	CCdlTkInterface* base = this;
       
   839 	while (base->Base())
       
   840 		base = base->Base();
       
   841 	return base;
       
   842 	}
       
   843 
       
   844 const CCdlTkInterface* CCdlTkInterface::UltimateBase() const
       
   845 	{
       
   846 	const CCdlTkInterface* base = this;
       
   847 	while (base->Base())
       
   848 		base = base->Base();
       
   849 	return base;
       
   850 	}
       
   851 
       
   852 CCdlTkInterface* CCdlTkInterface::UltimateExtension()
       
   853 	{
       
   854 	CCdlTkInterface* extension = this;
       
   855 	while (extension->Extension())
       
   856 		extension = extension->Extension();
       
   857 	return extension;
       
   858 	}
       
   859 
       
   860 const CCdlTkInterface* CCdlTkInterface::UltimateExtension() const
       
   861 	{
       
   862 	const CCdlTkInterface* extension = this;
       
   863 	while (extension->Extension())
       
   864 		extension = extension->Extension();
       
   865 	return extension;
       
   866 	}
       
   867 
       
   868 void CCdlTkInterface::MergeExtensions()
       
   869 	{
       
   870 	for (CCdlTkInterface* ext = Extension(); ext; ext = ext->Extension())
       
   871 		{
       
   872 		iHeader.MergeExtensionHeader(ext->iHeader);
       
   873 		iCpp.MergeExtensionCpp(ext->iCpp);
       
   874 		iApiList.MergeExtendedApi(*this, ext->iApiList);
       
   875 		iDataTypeTranslations.MergeExtensionTranslations(ext->iDataTypeTranslations);
       
   876 		}
       
   877 	SetExtension(0);
       
   878 	}
       
   879 
       
   880 string CCdlTkInterface::FileName() const
       
   881 	{
       
   882 	return iFileName;
       
   883 	}
       
   884 
       
   885 void CCdlTkInterface::SetFileName(const string& aFileName)
       
   886 	{
       
   887 	iFileName = aFileName;
       
   888 	}
       
   889 
       
   890 string CCdlTkInterface::AdditionalComment() const
       
   891 	{
       
   892 	return iAdditionalComment;
       
   893 	}
       
   894 
       
   895 void CCdlTkInterface::SetAdditionalComment(const string& aAdditionalComment)
       
   896 	{
       
   897 	iAdditionalComment = aAdditionalComment;
       
   898 	}
       
   899 
       
   900 CCdlTkInterfaceHeader& CCdlTkInterface::Header()
       
   901 	{
       
   902 	return iHeader;
       
   903 	}
       
   904 
       
   905 const CCdlTkInterfaceHeader& CCdlTkInterface::Header() const
       
   906 	{
       
   907 	return iHeader;
       
   908 	}
       
   909 
       
   910 CCdlTkCpp& CCdlTkInterface::Cpp()
       
   911 	{
       
   912 	return iCpp;
       
   913 	}
       
   914 
       
   915 const CCdlTkCpp& CCdlTkInterface::Cpp() const
       
   916 	{
       
   917 	return iCpp;
       
   918 	}
       
   919 
       
   920 CCdlTkApiList& CCdlTkInterface::ApiList()
       
   921 	{
       
   922 	return iApiList;
       
   923 	}
       
   924 
       
   925 const CCdlTkApiList& CCdlTkInterface::ApiList() const
       
   926 	{
       
   927 	return iApiList;
       
   928 	}
       
   929 
       
   930 string CCdlTkInterface::NamespaceName() const
       
   931 	{
       
   932 	return CdlTkUtil::ToCpp(iHeader.Name());
       
   933 	}
       
   934 
       
   935 CCdlTkDataTypeTranslations& CCdlTkInterface::DataTypeTranslations()
       
   936 	{
       
   937 	return iDataTypeTranslations;
       
   938 	}
       
   939 
       
   940 const CCdlTkDataTypeTranslations& CCdlTkInterface::DataTypeTranslations() const
       
   941 	{
       
   942 	return iDataTypeTranslations;
       
   943 	}
       
   944 
       
   945 bool CCdlTkInterface::operator==(const CCdlTkInterface& aOther) const
       
   946 	{
       
   947 	return
       
   948 		iHeader == aOther.iHeader &&
       
   949 		iCpp == aOther.iCpp &&
       
   950 		iApiList == aOther.iApiList &&
       
   951 		iDataTypeTranslations == aOther.iDataTypeTranslations &&
       
   952 		!iExtension == !aOther.iExtension &&
       
   953 		(!iExtension || *iExtension == *aOther.iExtension);
       
   954 	}
       
   955 
       
   956 
       
   957 //
       
   958 // CCdlTkInterfaceList
       
   959 //
       
   960 
       
   961 CCdlTkInterfaceList::CCdlTkInterfaceList()
       
   962 	{
       
   963 	}
       
   964 
       
   965 CCdlTkInterfaceList::~CCdlTkInterfaceList()
       
   966 	{
       
   967 	for (iterator it = begin(); it != end(); ++it)
       
   968 		delete *it;
       
   969 	}
       
   970 
       
   971 
       
   972 }	// end of namespace CdlCompilerToolkit