opl16gen.cpp

来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 2,125 行 · 第 1/5 页

CPP
2,125
字号
						if (err)
							User::Leave(err);
						iNormalFlag=ETrue;
						appInfoFileWriter->AddIconL(*maskedBitmap);	// appInfoFileWriter now owns icon
						CleanupStack::Pop();			// maskedBitmap (now owned by writer)
						bitmapOnCleanup=EFalse;
						}
					}
				}
				break;
			case TOplToken::EPath:
				{
				TestFlagTokenAndTypeL(KOpl16AppPathFlag,TOplToken::EConstant,TOplToken::EString);
				TPtrC path=iLexer.Constant().AsStringL();
				if (path.Length()>KOpl16AppMaxPathLen)
					User::Leave(EErrBadStringLength);
				iPath.CopyF(path);
				if (iPath.Length()==0 || iPath[iPath.Length()-1]!='\\') // Need to add trailing
					{
					if (path.Length()==KOpl16AppMaxPathLen)
						User::Leave(EErrBadStringLength);
					iPath.Append('\\');
					}
				}
				break;

			case TOplToken::EEndA:
				endSeen=ETrue;
				break;
			default:
				User::Leave(EErrSyntax);
			}
		// EOS
		iLexer.LexL(TOplToken::EEos);
		}
	if (iTarget==EOplTargetER1)
		{
		if (bitmapOnCleanup)
			CleanupStack::PopAndDestroy();	// pop and destroy the bitmap that hasn't been added
		if (iNormalFlag==EFalse)	// if mask still required
			User::Leave(EErrIconMaskMissing);

		TApaAppCapabilityBuf buf(capability);
		User::LeaveIfError(appInfoFileWriter->SetCapability(buf));
		if ((iFlags&KOpl16AppCaptionFlag)==0)
			appInfoFileWriter->AddCaptionL(User::Language(),name); // Use APP <name> as caption

		appInfoFileWriter->StoreL();
		CleanupStack::PopAndDestroy();	// appInfoFileWriter
		}
	CleanupStack::PopAndDestroy(); // fs
	}


const CCnvCharacterSetConverter* COpl16App::LoadUnicodeConverterLC()
//
// Locate and load the convchar converter
//
	{
	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();//push convertor.

	RFs fsSession; 
	User::LeaveIfError(fsSession.Connect());
	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=characterSetConverter->CreateArrayOfCharacterSetsAvailableL(fsSession);
	CleanupStack::PushL(arrayOfCharacterSetsAvailable);//push array of.

	if (arrayOfCharacterSetsAvailable->Count()==0)
		User::Leave(KErrNotFound);

	//!!TODO Ask David B about which charSetConvertors are going to be most popular...
	//Or has this changed anyway? See ConvertToUnicodeFromNative8BitBuild().
	TInt gotIt=EFalse;
	for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
		{
		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
		characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fsSession);
		TPtrC charactersSetName;
		charactersSetName.Set(charactersSet.Name());
		_LIT(KCharSetName,"Code Page 1252");
		if (charactersSetName.Find(KCharSetName)==0)
			{
			gotIt=ETrue;
			break;
			}
		}
	if (gotIt==EFalse)
		User::Leave(KErrNotFound);

	TInt KUidCodePage1252=0x100012b6;

	characterSetConverter->PrepareToConvertToOrFromL(KUidCodePage1252, *arrayOfCharacterSetsAvailable, fsSession);
	fsSession.Close();
	return characterSetConverter;
	}


void COpl16App::FromUnicodeL(TPtrC16& aUnicode,TPtr8& aNarrow)
	{
	const CCnvCharacterSetConverter* converter=LoadUnicodeConverterLC();
	TInt state=CCnvCharacterSetConverter::KStateDefault;
	converter->ConvertFromUnicode(aNarrow,aUnicode,state);
	if (state!=CCnvCharacterSetConverter::KStateDefault)
		User::Leave(KErrNotSupported);
	CleanupStack::PopAndDestroy(2); // arrayOfCharacterSetsAvailable and characterSetConverter
	}

					 
COpl16App::COpl16App(TOplTranTarget aTarget,COplLexerBase& aLexer)
	: iTarget(aTarget), iType(0), iFlags(0), iLexer(aLexer),iNormalFlag(ETrue)
//
// C'tor
//
	{

	}


void COpl16App::TestFlagTokenAndTypeL(TUint aFlag,TOplToken aToken,TOplToken::TType aType)
//
// Called when trying to add component
// If we've seen it already that's a syntax error
//
	{
	
	if (iFlags&aFlag)
		User::Leave(EErrSyntax);
	iFlags|=aFlag;
	iLexer.LexL(aToken);
	if (iLexer.Type()!=aType)
		User::Leave(EErrSyntax);
	}

////////////////////////////////////////////////////////////////
// 
// COpl16PcodeConverter
//
////////////////////////////////////////////////////////////////
const TInt KOpl16PcodeConvStackGran=8;
const TInt KOpl16PcodeConvLabelsGran=16;
class TTranslateError;

class COpl16PcodeConverter : public CBase
	{
public:
	static COpl16PcodeConverter* NewL();
	static COpl16PcodeConverter* NewLC();
	~COpl16PcodeConverter();
	inline void SetErrorOffset(TInt aQcodeOffset) { iErrorPos=aQcodeOffset;}
	TInt RunL(CBufBase& aPcodeStream,
				ROpoWriteStream& aQcodeStream,
				TTranslateError& anError,
				CTextTranslator::TDebugFlag aFlag);
	inline TInt MaxStackDepth() { return iMaxStackDepth;}
private:
	void ConvertPcodeL(RReadStream& aPcodeStream,ROpoWriteStream& aQcodeStream,
			TTranslateError& anError,CTextTranslator::TDebugFlag aFlag);
	void LabelReferenceL(RReadStream& aPcodeStream, ROpoWriteStream& aQcodeStream,TInt aBase);
	
	// Stack monitoring
	void AddToStackL(TOplToken::TType aType);
	void AddToStackL(TUint byteCount);
	TUint AddToStackL(TPcode::TIdentifierSide aSide ,TOplToken::TType aType);
	void AdjustStackForCallL(TOplToken::TType aReturnType);
	void RemoveFromStack(TOplToken::TType aType);
	TUint SizeOnStack(TOplToken::TType aType);
	inline void ZeroStack() {iStackDepth=0;}
	void ConstructL();
	COpl16PcodeConverter();
private:
	TUint iStackDepth;
	TUint iMaxStackDepth;
	TInt iErrorPos;
	CTranStackFlat<TUint>* iStackDepths;
	CArrayFixSeg<COplSymbol*>* iLabels;
	};

	
static const TUint8 procByNameTypeBytes[]={'%','&',0,'$'};
static const TUint8 casts[TOplToken::EMaxNormalType][TOplToken::EMaxNormalType]= // TQcode16::EExtended is type mismatch error 
	{
	// WORD, LONG, DOUBLE, STRING, UWORD 
	{ 0, TQcode16::EWordToLong, TQcode16::EWordToDouble,	TQcode16::EExtended,0 }, // WORD
	{TQcode16::ELongToWord, 0, TQcode16::ELongToDouble,TQcode16::EExtended, TQcode16::ELongToUword},  // LONG
	{TQcode16::EDoubleToWord,TQcode16::EDoubleToLong, 0,TQcode16::EExtended, TQcode16::EDoubleToUword}, // Double 
	{TQcode16::EExtended,	TQcode16::EExtended,		TQcode16::EExtended, 	0,	TQcode16::EExtended}, // String 
	{ 0,	TQcode16::EWordToLong, TQcode16::EWordToDouble,	TQcode16::EExtended,0},  // UWORD - dummy row really
	};

static const TUint8 operators[]=
	{
	0,
	TQcode16::ELessThan,
	TQcode16::ELessThanEq,
	TQcode16::EGreaterThan,
	TQcode16::EGreaterThanEq,
	TQcode16::EEqual,
	TQcode16::ENotEqual,
	TQcode16::EAddition,
	TQcode16::ESubtraction,
	TQcode16::EMultiply,
	TQcode16::EDivide,
	TQcode16::EPower,
	TQcode16::EAnd,
	TQcode16::EOr,
	TQcode16::ENot,
	TQcode16::EUnaryMinus,
	0,
	0,
	0,
	0,
	TQcode16::EPercLess,
	TQcode16::EPercGreater,
	TQcode16::EPercPlus,
	TQcode16::EPercMinus,
	TQcode16::EPercMultiply,													
	TQcode16::EPercDivide
	};

typedef TUint16 TUintCode; // Size of values to store in the table
static const TUintCode QcodeTable[TOplKeyword::EMaxCode]=
	{
	TUintCode(TQcode16::EAppend),TUintCode(TQcode16::EAppendSprite),TUintCode(TQcode16::EAt),TUintCode(TQcode16::EBack),TUintCode(TQcode16::EBeep),
	TUintCode(TQcode16::EExtended),TUintCode(TQcode16::EBusy),TUintCode(TQcode16::ECache),TUintCode(TQcode16::ECacheHdr),TUintCode(TQcode16::ECacheRec),
	TUintCode(TQcode16::ECacheTidy),TUintCode(TQcode16::EChangeSprite),TUintCode(TQcode16::EClose),TUintCode(TQcode16::ECloseSprite),TUintCode(TQcode16::ECls),
	TUintCode(TQcode16::ECompress),TUintCode(TQcode16::EExtended),TUintCode(TQcode16::ECopy),TUintCode(TQcode16::ECreate),TUintCode(TQcode16::ECursor),
	TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EdItem),
	TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EdItem),
	TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EdItem),TUintCode(TQcode16::EDefaultWin),TUintCode(TQcode16::EDelete),TUintCode(TQcode16::EDiamInit),
	TUintCode(TQcode16::EDiamPos),TUintCode(TQcode16::EdInit),TUintCode(TQcode16::EdInitS),TUintCode(TQcode16::EDrawSprite),TUintCode(TQcode16::EEdit),
	TUintCode(TQcode16::EErase),TUintCode(TQcode16::EEscape),TUintCode(TQcode16::EFirst),TUintCode(TQcode16::EFont),TUintCode(TQcode16::EFreeAlloc),
	TUintCode(TQcode16::EgAt),TUintCode(TQcode16::EgBorder),TUintCode(TQcode16::EgBox),TUintCode(TQcode16::EgButton),TUintCode(TQcode16::EgClock),
	TUintCode(TQcode16::EgClose),TUintCode(TQcode16::EgCls),TUintCode(TQcode16::EgCopy),TUintCode(TQcode16::EgDrawObject), TUintCode(TQcode16::EGetEvent),
	TUintCode(TQcode16::EgFill),TUintCode(TQcode16::EgFont),TUintCode(TQcode16::EgGMode),TUintCode(TQcode16::EgGrey),TUintCode(TQcode16::EgInfo),
	TUintCode(TQcode16::EgInvert),TUintCode(TQcode16::EgIPrint),TUintCode(TQcode16::EgLineBy),TUintCode(TQcode16::EgLineTo),TUintCode(TQcode16::EgMove),
	TUintCode(TQcode16::EgOrder),TUintCode(TQcode16::EExtended),TUintCode(TQcode16::EgPatt),TUintCode(TQcode16::EgPeekLine),TUintCode(TQcode16::EgPoly),
	TUintCode(TQcode16::EgPrint),TUintCode(TQcode16::EgPrintSpace),TUintCode(TQcode16::EgPrintB),TUintCode(TQcode16::EgSaveBit),TUintCode(TQcode16::EgScroll),
	TUintCode(TQcode16::EgSetWin),TUintCode(TQcode16::EgStyle),TUintCode(TQcode16::EgTMode),TUintCode(TQcode16::EgUnloadFont),TUintCode(TQcode16::EgUpdate),
	TUintCode(TQcode16::EgUse),TUintCode(TQcode16::EgVisible),TUintCode(TQcode16::EgXBorder),TUintCode(TQcode16::EgXPrint),TUintCode(TQcode16::EInput),
	TUintCode(TQcode16::EIoSignal),TUintCode(TQcode16::EIoWaitStat),TUintCode(TQcode16::EIoYield),TUintCode(TQcode16::ELast),TUintCode(TQcode16::ELclose),
	TUintCode(TQcode16::ELinkLib),TUintCode(TQcode16::ELoadm),TUintCode(TQcode16::ELock),TUintCode(TQcode16::ELopen),TUintCode(TQcode16::ELprintValue),
	TUintCode(TQcode16::ELprintSpace),TUintCode(TQcode16::ELprintCrLf),TUintCode(TQcode16::EmCard),TUintCode(TQcode16::EmInit),TUintCode(TQcode16::EMkDir),
	TUintCode(TQcode16::ENext),TUintCode(TQcode16::EOdbInfo),TUintCode(TQcode16::EOff),TUintCode(TQcode16::EOffTime),TUintCode(TQcode16::EExtended),		
	TUintCode(TQcode16::EOpen),TUintCode(TQcode16::EOpenr),TUintCode(TQcode16::EPause),TUintCode(TQcode16::EPokeByte),TUintCode(TQcode16::EPokeDouble),
	TUintCode(TQcode16::EPokeLong),TUintCode(TQcode16::EPokeString),TUintCode(TQcode16::EPokeWord),TUintCode(TQcode16::EPosition),TUintCode(TQcode16::EPosSprite),
	TUintCode(TQcode16::EPrintValue),TUintCode(TQcode16::EPrintSpace),TUintCode(TQcode16::EPrintCrLf),TUintCode(TQcode16::ERaise),TUintCode(TQcode16::ERandomize),
	TUintCode(TQcode16::ERename),TUintCode(TQcode16::EReturnValue),TUintCode(TQcode16::EReturnNull),TUintCode(TQcode16::ERmDir),TUintCode(TQcode16::EScreen),
	TUintCode(TQcode16::EgScreen),TUintCode(TQcode16::EScreenInfo),TUintCode(TQcode16::ESecsToDate),TUintCode(TQcode16::ESetName),TUintCode(TQcode16::ESetPath),
	TUintCode(TQcode16::EStatusWin),TUintCode(TQcode16::EStop),TUintCode(TQcode16::EStyle),TUintCode(TQcode16::ETrap),TUintCode(TQcode16::EUnloadm),
	TUintCode(TQcode16::EUpdate),TUintCode(TQcode16::EUse),TUintCode(TQcode16::EUseSprite),TUintCode(TQcode16::EModify),TUintCode(TQcode16::EInsert),
	TUintCode(TQcode16::ECancel), TUintCode(TQcode16::EPut),TUintCode(TQcode16::EDeleteTable),TUintCode(TQcode16::EgCircle),TUintCode(TQcode16::EgEllipse),
	TUintCode(TQcode16::EGotoMark),TUintCode(TQcode16::EKillMark),TUintCode(TQcode16::EReturnFromEval),TUintCode(TQcode16::EGetEvent32),TUintCode(TQcode16::EGetEventa32),
	TUintCode(TQcode16::EGcolor),TUintCode(TQcode16::ESetflags),TUintCode(TQcode16::ESetdoc),TUintCode(TQcode16::EDaysToDate),TUintCode(TQcode16::EGinfo32),
	TUintCode(TQcode16::EIowaitstat32),TUintCode(TQcode16::ECompact),TUintCode(TQcode16::EBeginTrans),TUintCode(TQcode16::ECommitTrans),TUintCode(TQcode16::ERollBack),
	TUintCode(TQcode16::EClearflags),TUintCode(TQcode16::EPointerFilter),TUintCode(TQcode16::EmCasc),/*TUintCode(TQcode16::EdCheckBox),*/TUintCode(TQcode16::EgSetPenWidth),
	TUintCode(TQcode16::EdEditMulti),TUintCode(TQcode16::EGcolorinfo),TUintCode(TQcode16::EGcolorbackground),TUintCode(TQcode16::EmCardX),TUintCode(TQcode16::ESetHelp),
	TUintCode(TQcode16::EShowHelp),TUintCode(TQcode16::ESetHelpUid)
	};

typedef TUint8 TUintFunc; // Type used for entries in this table
static const TUintFunc FunctionTable[TOplFunction::EMaxNumber]=
	{
	TUintFunc(TQcode16::EAddr), TUintFunc(TQcode16::EAsc), TUintFunc(TQcode16::ECall), TUintFunc(TQcode16::ECount), TUintFunc(TQcode16::EDay),
	TUintFunc(TQcode16::EDow), TUintFunc(TQcode16::EEof), TUintFunc(TQcode16::EErr), TUintFunc(TQcode16::EExist), TUintFunc(TQcode16::EFind),
	TUintFunc(TQcode16::EGet), TUintFunc(TQcode16::EIoA), TUintFunc(TQcode16::EIoW), TUintFunc(TQcode16::EIoOpen), TUintFunc(TQcode16::EIoWrite),
	TUintFunc(TQcode16::EIoRead), TUintFunc(TQcode16::EIoClose), TUintFunc(TQcode16::EIoWait), TUintFunc(TQcode16::EHour), TUintFunc(TQcode16::EKey),
	TUintFunc(TQcode16::ELen), TUintFunc(TQcode16::ELoc), TUintFunc(TQcode16::EMinute), TUintFunc(TQcode16::EMonth), TUintFunc(TQcode16::EPeekB),
	TUintFunc(TQcode16::EPeekW), TUintFunc(TQcode16::EPos), TUintFunc(TQcode16::ERecSize), TUintFunc(TQcode16::ESecond), TUintFunc(TQcode16::EUsr),
	TUintFunc(TQcode16::EYear), TUintFunc(TQcode16::EWeek), TUintFunc(TQcode16::EIoSeek), TUintFunc(TQcode16::EKMod), TUintFunc(TQcode16::EKeyA),
	TUintFunc(TQcode16::EKeyC), TUintFunc(TQcode16::EgCreate), TUintFunc(TQcode16::EgCreateBit), TUintFunc(TQcode16::EgLoadBit), TUintFunc(TQcode16::EgLoadFont),
	TUintFunc(TQcode16::EgRank), TUintFunc(TQcode16::EgIdentity), TUintFunc(TQcode16::EgX), TUintFunc(TQcode16::EgY), TUintFunc(TQcode16::EgWidth),
	TUintFunc(TQcode16::EgHeight), TUintFunc(TQcode16::EgOriginX), TUintFunc(TQcode16::EgOriginY), TUintFunc(TQcode16::EgTWidth), TUintFunc(TQcode16::EgPrintClip),
	TUintFunc(TQcode16::ETestEvent), TUintFunc(TQcode16::EOs), TUintFunc(TQcode16::EMenu), TUintFunc(TQcode16::EDialog), TUintFunc(TQcode16::EAlert),
	TUintFunc(TQcode16::ECreateSprite), TUintFunc(TQcode16::ELoadLib), TUintFunc(TQcode16::EUnloadLib), TUintFunc(TQcode16::EFindLib), TUintFunc(TQcode16::EGetLibH),
	TUintFunc(TQcode16::ENewObj), TUintFunc(TQcode16::ENewObjH), TUintFunc(TQcode16::ESend), TUintFunc(TQcode16::EEnterSend), TUintFunc(TQcode16::EEnterSend0),
	TUintFunc(TQcode16::EAlloc), TUintFunc(TQcode16::EReAlloc), TUintFunc(TQcode16::EAdjustAlloc), TUintFunc(TQcode16::ELenAlloc), TUintFunc(TQcode16::EIoc),
	TUintFunc(TQcode16::EUAdd), TUintFunc(TQcode16::EUSub), TUintFunc(TQcode16::EIoCancel), TUintFunc(TQcode16::EStatWinInfo), TUintFunc(TQcode16::EFindField),
	TUintFunc(TQcode16::EDays), TUintFunc(TQcode16::EIAbs), TUintFunc(TQcode16::EInt), TUintFunc(TQcode16::EPeekL), TUintFunc(TQcode16::ESpace),
	TUintFunc(TQcode16::EDateToSecs), TUintFunc(TQcode16::EAbs), TUintFunc(TQcode16::EACos), TUintFunc(TQcode16::EASin), TUintFunc(TQcode16::EATan),
	TUintFunc(TQcode16::ECos), TUintFunc(TQcode16::EDeg), TUintFunc(TQcode16::EExp), TUintFunc(TQcode16::EFlt), TUintFunc(TQcode16::EIntF),
	TUintFunc(TQcode16::ELn), TUintFunc(TQcode16::ELog), TUintFunc(TQcode16::EPeekF), TUintFunc(TQcode16::EPi), TUintFunc(TQcode16::ERad),
	TUintFunc(TQcode16::ERnd), TUintFunc(TQcode16::ESin), TUintFunc(TQcode16::ESqr), TUintFunc(TQcode16::ETan), TUintFunc(TQcode16::EVal),
	TUintFunc(TQcode16::EMax), TUintFunc(TQcode16::EMean), TUintFunc(TQcode16::EMin), TUintFunc(TQcode16::EStd), TUintFunc(TQcode16::ESum),
	TUintFunc(TQcode16::EVar), TUintFunc(TQcode16::EEval), TUintFunc(TQcode16::EChrS), TUintFunc(TQcode16::EDatim), TUintFunc(TQcode16::EDayNameS),
	TUintFunc(TQcode16::EDirS), TUintFunc(TQcode16::EErrS), TUintFunc(TQcode16::EFixS), TUintFunc(TQcode16::EGenS), TUintFunc(TQcode16::EGetS),
	TUintFunc(TQcode16::EHexS), TUintFunc(TQcode16::EKeyS), TUintFunc(TQcode16::ELeftS), TUintFunc(TQcode16::ELowerS), TUintFunc(TQcode16::EMidS),
	TUintFunc(TQcode16::EMonthS), TUintFunc(TQcode16::ENumS), TUintFunc(TQcode16::EPeekS), TUintFunc(TQcode16::EReptS), TUintFunc(TQcode16::ERightS),
	TUintFunc(TQcode16::ESciS), TUintFunc(TQcode16::EUpperS), TUintFunc(TQcode16::EUserS), TUintFunc(TQcode16::EGetCmdS), TUintFunc(TQcode16::ECmdS),
	TUintFunc(TQcode16::EParseS), TUintFunc(TQcode16::ESAddr), TUintFunc(TQcode16::EGreyCreate),TUintFunc(TQcode16::EIoOpenX), TUintFunc(TQcode16::EMenuX),
	TUintFunc(TQcode16::EBookMark), TUintFunc(TQcode16::EGetEventC), TUintFunc(TQcode16::EErrxS), TUintFunc(TQcode16::EInTrans), TUintFunc(TQcode16::EGetDocS),
	TUintFunc(TQcode16::EMPopup), TUintFunc(TQcode16::ESize) 
	};
// Sizes of the variable types for the purposes of accounting for runtime stack usage.
const TUint KOpl16SizeOfLeftSideReference=6;
const TInt KOpl16SizeOfWord=2;
const TInt KOpl16SizeOfLong=4;
const TInt KOpl16SizeOfReal=8;
const TInt KOpl16SizeOfString=0; // Don't keep track of stack for strings.
const TInt KOpl16SizeOfUword=2;

static const TUint8 stackSizes[TOplToken::EMaxNormalType]=
	{
	KOpl16SizeOfWord,KOpl16SizeOfLong,KOpl16SizeOfReal,KOpl16SizeOfString,KOpl16SizeOfUword
	};


static TInt StatementQcodeL(RWriteStream& aStream,TPcodeCommand& aCommand)
//
// Puts out the qcode for a command, checking first to see if it's one of those completely mental
// dialog command which have an index after them
//	
	{
	TUint code=QcodeTable[aCommand.Code()];

    if (code==TQcode16::EdItem)
		{
		aStream<<TQcode16(code); // relies on the fact that they are not trappable
		code=aCommand.Code()-TOplKeyword::EDtext; // Relies on knowledge  that these are contiguous
		}
	return code;
	}

COpl16PcodeConverter* COpl16PcodeConverter::NewLC()
	{
	COpl16PcodeConverter *pC=new(ELeave) COpl16PcodeConverter();
	CleanupStack::PushL(pC);
	pC->ConstructL();
	return pC;
	}

COpl16PcodeConverter* COpl16PcodeConverter::NewL()
	{
	COpl16PcodeConverter *pC=NewLC();
	CleanupStack::Pop();
	return pC;
	}

COpl16PcodeConverter::COpl16PcodeConverter()
	{
	iErrorPos=KOplNoErrorLocation;
	}

COpl16PcodeConverter::~COpl16PcodeConverter()
	{
	delete iStackDepths;
	delete iLabels;
	}

void COpl16PcodeConverter::ConstructL()
	{
	
	iStackDepths=new(ELeave) CTranStackFlat<TUint>(KOpl16PcodeConvStackGran);
	iLabels=new(ELeave) CArrayFixSeg<COplSymbol *>(KOpl16PcodeConvLabelsGran);
	}

void COpl16PcodeConverter::ConvertPcodeL(
//
// Converts a Pcode stream into a Qcode stream
//
//	
	RReadStream& aPcode,
	ROpoWriteStream& aQcode,
	TTranslateError& anError,
	CTextTranslator::TDebugFlag aFlag)
	{

	TUint vectorLabelsCount=0;
	TInt vectorBase=0;
	if (iErrorPos!=KOplNoErrorLocation)
		iErrorPos+=aQcode.SizeL(); // Account for anything that's in the Qcode buffer already

	TPcode next;
	TStreamPos vectorPatchPos=KStreamBeginning;

	FOREVER
		{

		aPcode>>next;
		anError.SetPosition(next.Offset()); // So that we report errors in the right place.

		switch (next.Code())
			{
			case TPcode::EStatement: // If in Debig mode we put out the statement command
				{
				if (aFlag!=CTextTranslator::EDebug)
					continue; // Skip all the size checking etc.
				if (next.Offset()>KMaxTUint16)
					aQcode<<TQcode16(TQcode16::EDebugStatement32)<<TUint32(next.Offset());
				else
					aQcode<<TQcode16(TQcode16::EDebugStatement16)<<TUint16(next.Offset());
				break;
				}
			case TPcode::EConstant:
				{
				CPcodeConstant *constant=CPcodeConstant::NewLC(aPcode);
				AddToStackL(constant->Type());

				switch (constant->Type())
					{
					default:
						Panic(EOpl16GenUnknownConstantType);
					case TOplToken::EWord:
						{
						TInt val=constant->Int();
						if (val<KMinTInt8 || val>KMaxTInt8)
							(aQcode<<TQcode16(TQcode16::EConstant|TOplToken::EWord)).WriteInt16L(val);
						else
							(aQcode<<TQcode16(TQcode16::EStackByteAsWord)).WriteInt8L(val);
						break;
						}
					case TOplToken::ELong:
						{
						TInt32 val=constant->Int();
						if (val>=KMinTInt8 && val<=KMaxTInt8)
							(aQcode<<TQcode16(TQcode16::EStackByteAsLong)).WriteInt8L(val);
						else if (val>=KMinTInt16 && val<=KMaxTInt16)
							(aQcode<<TQcode16(TQcode16::EStackWordAsLong)).WriteInt16L(val);
						else
							aQcode<<TQcode16(TQcode16::EConstant|TOplToken::ELong)<<val;
						break;
						}
					case TOplToken::EReal:
						aQcode<<TQcode16(TQcode16::EConstant|TOplToken::EReal)<<constant->Real();
						break;
					case TOplToken::EString:
						aQcode<<TQcode16(TQcode16::EConstant|TOplToken::EString)<<TLbc(constant->String());

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?