/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
void SbiParser::If()
{
sal_uInt32 nEndLbl;
SbiToken eTok = NIL; // ignore end-tokens
SbiExpression aCond( this );
aCond.Gen();
TestToken( THEN ); if( IsEoln( Next() ) )
{ // At the end of each block a jump to ENDIF must be inserted, // so that the condition is not evaluated again at ELSEIF. // The table collects all jump points.
constexpr sal_uInt16 JMP_TABLE_SIZE = 100;
sal_uInt32 pnJmpToEndLbl[JMP_TABLE_SIZE]; // 100 ELSEIFs allowed
sal_uInt16 iJmp = 0; // current table index
void SbiParser::For()
{ bool bForEach = ( Peek() == EACH ); if( bForEach )
Next();
SbiExpression aLvalue( this, SbOPERAND ); if (!aLvalue.IsVariable())
{
bAbort = true; return; // the error is already set in SbiExpression ctor
}
aLvalue.Gen(); // variable on the Stack
if( bForEach )
{
TestToken( IN_ );
SbiExpression aCollExpr( this, SbOPERAND );
aCollExpr.Gen(); // Collection var to for stack
TestEoln();
aGen.Gen( SbiOpcode::INITFOREACH_ );
} else
{
TestToken( EQ );
SbiExpression aStartExpr( this );
aStartExpr.Gen();
TestToken( TO );
SbiExpression aStopExpr( this );
aStopExpr.Gen(); if( Peek() == STEP )
{
Next();
SbiExpression aStepExpr( this );
aStepExpr.Gen();
} else
{
SbiExpression aOne( this, 1, SbxINTEGER );
aOne.Gen();
}
TestEoln(); // The stack has all 4 elements now: variable, start, end, increment // bind start value
aGen.Gen( SbiOpcode::INITFOR_ );
}
sal_uInt32 nLoop = aGen.GetPC(); // do tests, maybe free the stack
sal_uInt32 nEndTarget = aGen.Gen( SbiOpcode::TESTFOR_, 0 );
OpenBlock( FOR );
StmntBlock( NEXT );
aGen.Gen( SbiOpcode::NEXT_ );
aGen.Gen( SbiOpcode::JUMP_, nLoop ); // are there variables after NEXT? if( Peek() == SYMBOL )
{
SbiExpression aVar( this, SbOPERAND ); if( aVar.GetRealVar() != aLvalue.GetRealVar() )
Error( ERRCODE_BASIC_EXPECTED, aLvalue.GetRealVar()->GetName() );
}
aGen.BackChain( nEndTarget );
CloseBlock();
}
// WITH .. END WITH
namespace
{ // Generate a '{_with_library.module_offset} = rVar' // Use the {_with_library.module_offset} in OpenBlock // The name of the variable can't be used by user: a name like [{_with_library.module_offset}] // is valid, but not without the square brackets struct WithLocalVar
{
WithLocalVar(SbiParser& rParser, SbiExpression& rVar)
: m_rParser(rParser)
, m_aWithParent(createLocalVar(rParser))
{ // Assignment
m_aWithParent.Gen();
rVar.Gen();
m_rParser.aGen.Gen(SbiOpcode::PUTC_);
}
void SbiParser::On()
{
SbiToken eTok = Peek();
OUString aString = SbiTokenizer::Symbol(eTok); if (aString.equalsIgnoreAsciiCase("ERROR"))
{
eTok = ERROR_; // Error comes as SYMBOL
} if( eTok != ERROR_ && eTok != LOCAL )
{
OnGoto();
} else
{ if( eTok == LOCAL )
{
Next();
}
Next (); // no more TestToken, as there'd be an error otherwise
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.