| 1 |
/* |
| 2 |
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2020 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 31 авг. 2019 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <lsp-plug.in/common/types.h> |
| 23 |
#include <lsp-plug.in/fmt/java/const.h> |
| 24 |
#include <lsp-plug.in/fmt/java/Object.h> |
| 25 |
|
| 26 |
namespace lsp |
| 27 |
{ |
| 28 |
namespace java |
| 29 |
{ |
| 30 |
size_t size_of(ftype_t type) |
| 31 |
{ |
| 32 |
switch (type) |
| 33 |
{ |
| 34 |
case JFT_BYTE: return sizeof(uint8_t); |
| 35 |
case JFT_CHAR: return sizeof(lsp_utf16_t); |
| 36 |
case JFT_DOUBLE: return sizeof(double_t); |
| 37 |
case JFT_FLOAT: return sizeof(float_t); |
| 38 |
case JFT_INTEGER: return sizeof(uint32_t); |
| 39 |
case JFT_LONG: return sizeof(uint64_t); |
| 40 |
case JFT_SHORT: return sizeof(uint16_t); |
| 41 |
case JFT_BOOL: return sizeof(uint8_t); |
| 42 |
case JFT_ARRAY: return sizeof(Object *); |
| 43 |
case JFT_OBJECT: return sizeof(Object *); |
| 44 |
default: break; |
| 45 |
} |
| 46 |
return sizeof(size_t); |
| 47 |
} |
| 48 |
|
| 49 |
size_t aligned_offset(size_t offset, ftype_t type) |
| 50 |
{ |
| 51 |
// Currently we can not consider offsets being power of 2, use divides |
| 52 |
size_t size = size_of(type); |
| 53 |
size_t tail = offset % size; |
| 54 |
return (tail) ? offset - tail + size : offset; |
| 55 |
} |
| 56 |
|
| 57 |
bool is_primitive(ftype_t type) |
| 58 |
{ |
| 59 |
switch (type) |
| 60 |
{ |
| 61 |
case JFT_BYTE: |
| 62 |
case JFT_CHAR: |
| 63 |
case JFT_DOUBLE: |
| 64 |
case JFT_FLOAT: |
| 65 |
case JFT_INTEGER: |
| 66 |
case JFT_LONG: |
| 67 |
case JFT_SHORT: |
| 68 |
case JFT_BOOL: |
| 69 |
return true; |
| 70 |
default: |
| 71 |
break; |
| 72 |
} |
| 73 |
return false; |
| 74 |
} |
| 75 |
|
| 76 |
bool is_reference(ftype_t type) |
| 77 |
{ |
| 78 |
switch (type) |
| 79 |
{ |
| 80 |
case JFT_ARRAY: |
| 81 |
case JFT_OBJECT: |
| 82 |
return true; |
| 83 |
default: |
| 84 |
break; |
| 85 |
} |
| 86 |
return false; |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
|