1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <basic/sberrors.hxx>
25 const static sal_uInt32 UP_LIMIT
=0xFFFFFF00;
27 // The SbiBuffer will be expanded in increments of at least 16 Bytes.
28 // This is necessary, because many classes emanate from a buffer length
31 SbiBuffer::SbiBuffer( SbiParser
* p
, short n
)
34 n
= ( (n
+ 15 ) / 16 ) * 16;
43 SbiBuffer::~SbiBuffer()
47 // Reach out the buffer
48 // This lead to the deletion of the buffer!
50 char* SbiBuffer::GetBuffer()
52 char* p
= pBuf
.release();
57 // Test, if the buffer can contain n Bytes.
58 // In case of doubt it will be enlarged
60 bool SbiBuffer::Check( sal_Int32 n
)
66 if( nOff
+ n
> nSize
)
79 if( ( nSize
+ nn
) > UP_LIMIT
)
85 p
= new char [nSize
+ nn
];
89 pParser
->Error( ERRCODE_BASIC_PROG_TOO_LARGE
);
96 if( nSize
) memcpy( p
, pBuf
.get(), nSize
);
98 pCur
= pBuf
.get() + nOff
;
105 // Patch of a Location
107 void SbiBuffer::Patch( sal_uInt32 off
, sal_uInt32 val
)
109 if( ( off
+ sizeof( sal_uInt32
) ) < nOff
)
111 sal_uInt16 val1
= static_cast<sal_uInt16
>( val
& 0xFFFF );
112 sal_uInt16 val2
= static_cast<sal_uInt16
>( val
>> 16 );
113 sal_uInt8
* p
= reinterpret_cast<sal_uInt8
*>(pBuf
.get()) + off
;
114 *p
++ = static_cast<char>( val1
& 0xFF );
115 *p
++ = static_cast<char>( val1
>> 8 );
116 *p
++ = static_cast<char>( val2
& 0xFF );
117 *p
= static_cast<char>( val2
>> 8 );
121 // Forward References upon label and procedures
122 // establish a linkage. The beginning of the linkage is at the passed parameter,
123 // the end of the linkage is 0.
125 void SbiBuffer::Chain( sal_uInt32 off
)
131 sal_uInt32 val1
= (nOff
& 0xFFFF);
132 sal_uInt32 val2
= (nOff
>> 16);
135 ip
= reinterpret_cast<sal_uInt8
*>(pBuf
.get()) + i
;
136 sal_uInt8
* pTmp
= ip
;
137 i
= *pTmp
++; i
|= *pTmp
++ << 8; i
|= *pTmp
++ << 16; i
|= *pTmp
++ << 24;
141 pParser
->Error( ERRCODE_BASIC_INTERNAL_ERROR
, "BACKCHAIN" );
144 *ip
++ = static_cast<char>( val1
& 0xFF );
145 *ip
++ = static_cast<char>( val1
>> 8 );
146 *ip
++ = static_cast<char>( val2
& 0xFF );
147 *ip
= static_cast<char>( val2
>> 8 );
152 void SbiBuffer::operator +=( sal_Int8 n
)
156 *pCur
++ = static_cast<char>(n
);
161 bool SbiBuffer::operator +=( sal_uInt8 n
)
165 *pCur
++ = static_cast<char>(n
);
175 void SbiBuffer::operator +=( sal_Int16 n
)
179 *pCur
++ = static_cast<char>( n
& 0xFF );
180 *pCur
++ = static_cast<char>( n
>> 8 );
185 bool SbiBuffer::operator +=( sal_uInt16 n
)
189 *pCur
++ = static_cast<char>( n
& 0xFF );
190 *pCur
++ = static_cast<char>( n
>> 8 );
200 bool SbiBuffer::operator +=( sal_uInt32 n
)
204 sal_uInt16 n1
= static_cast<sal_uInt16
>( n
& 0xFFFF );
205 sal_uInt16 n2
= static_cast<sal_uInt16
>( n
>> 16 );
206 operator +=(n1
) && operator +=(n2
);
215 void SbiBuffer::operator +=( sal_Int32 n
)
217 operator +=( static_cast<sal_uInt32
>(n
) );
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */