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 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;
42 SbiBuffer::~SbiBuffer()
46 // Reach out the buffer
47 // This lead to the deletion of the buffer!
49 char* SbiBuffer::GetBuffer()
51 char* p
= pBuf
.release();
56 // Test, if the buffer can contain n Bytes.
57 // In case of doubt it will be enlarged
59 bool SbiBuffer::Check( sal_Int32 n
)
65 if( nOff
+ n
> nSize
)
78 if( ( nSize
+ nn
) > UP_LIMIT
)
84 p
= new char [nSize
+ nn
];
88 pParser
->Error( ERRCODE_BASIC_PROG_TOO_LARGE
);
95 if( nSize
) memcpy( p
, pBuf
.get(), nSize
);
97 pCur
= pBuf
.get() + nOff
;
104 // Patch of a Location
106 void SbiBuffer::Patch( sal_uInt32 off
, sal_uInt32 val
)
108 if( ( off
+ sizeof( sal_uInt32
) ) < nOff
)
110 sal_uInt16 val1
= static_cast<sal_uInt16
>( val
& 0xFFFF );
111 sal_uInt16 val2
= static_cast<sal_uInt16
>( val
>> 16 );
112 sal_uInt8
* p
= reinterpret_cast<sal_uInt8
*>(pBuf
.get()) + off
;
113 *p
++ = static_cast<char>( val1
& 0xFF );
114 *p
++ = static_cast<char>( val1
>> 8 );
115 *p
++ = static_cast<char>( val2
& 0xFF );
116 *p
= static_cast<char>( val2
>> 8 );
120 // Forward References upon label and procedures
121 // establish a linkage. The beginning of the linkage is at the passed parameter,
122 // the end of the linkage is 0.
124 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 );
151 void SbiBuffer::operator +=( sal_Int8 n
)
155 *pCur
++ = static_cast<char>(n
);
160 bool SbiBuffer::operator +=( sal_uInt8 n
)
164 *pCur
++ = static_cast<char>(n
);
174 void SbiBuffer::operator +=( sal_Int16 n
)
178 *pCur
++ = static_cast<char>( n
& 0xFF );
179 *pCur
++ = static_cast<char>( n
>> 8 );
184 bool SbiBuffer::operator +=( sal_uInt16 n
)
188 *pCur
++ = static_cast<char>( n
& 0xFF );
189 *pCur
++ = static_cast<char>( n
>> 8 );
199 bool SbiBuffer::operator +=( sal_uInt32 n
)
203 sal_uInt16 n1
= static_cast<sal_uInt16
>( n
& 0xFFFF );
204 sal_uInt16 n2
= static_cast<sal_uInt16
>( n
>> 16 );
205 operator +=(n1
) && operator +=(n2
);
214 void SbiBuffer::operator +=( sal_Int32 n
)
216 operator +=( static_cast<sal_uInt32
>(n
) );
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */